package utl import ( "gopkg.in/gomail.v2" ) type Smtp struct { Host string Port int Username, Password string Alias string } func (self *Smtp) Send(to []string, subject, body string) error { m := gomail.NewMessage(/* gomail.SetEncoding(gomail.Base64) */) m.SetHeader("From", m.FormatAddress(self.Username, self.Alias)) m.SetHeader("To", to...) m.SetHeader("Subject", subject) m.SetHeader("text/html", body) //m.Attach("/tmp/foo.txt", // gomail.Rename("foo.txt"), // gomail.SetHeader(map[string][]string{ // "Content-Disposition": []string{ // fmt.Sprintf(`attachment; filename="%s"`, mime.QEncoding.Encode("UTF-8", name)), // }, // }), //) d := gomail.NewDialer(self.Host, self.Port, self.Username, self.Password) return d.DialAndSend(m) }