Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple attachments will be overwritten! #126

Open
anbaoyong opened this issue Oct 23, 2018 · 1 comment
Open

Multiple attachments will be overwritten! #126

anbaoyong opened this issue Oct 23, 2018 · 1 comment

Comments

@anbaoyong
Copy link

When I send two attachments at the same time, the content of the A attachment will be overwritten by the content of the attachment B, and the content of the attachment B is empty
My code is as follows,i appreciate it.

func SendMail(subject, body string, to []string, file map[string]*os.File) {

user := "[email protected]"
password := "123456"
m := gomail.NewMessage()
m.SetHeaders(map[string][]string{
	"From":    {m.FormatAddress("[email protected]", "test")},
	"To":      to,
	"Subject": {subject},
})
m.SetBody("text/html", body)
for fname, f := range file {
	m.Attach(fname, gomail.SetCopyFunc(func(w io.Writer) error {
		_, err := io.Copy(w, f)
		defer f.Close()
		return err
	}))
}

d := gomail.NewDialer("[email protected]", 587, user, password)
d.TLSConfig = &tls.Config{InsecureSkipVerify: true}
if err := d.DialAndSend(m); err != nil {
	log.Println(err)
}

}

func main() {

filemap := map[string]*os.File{}
f1,_:=os.Open("/control.sh")
f2,_:=os.Open("/build.sh")
filemap["control.sh"]=f1
filemap["build.sh"]=f2
SendMail("subject", "body", []string{"[email protected]"}, filemap)

}

@pedromorgan
Copy link

see #104 and #108

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants