smtp.go 767 B

123456789101112131415161718192021222324252627282930
  1. package utl
  2. import (
  3. "gopkg.in/gomail.v2"
  4. )
  5. type Smtp struct {
  6. Host string
  7. Port int
  8. Username, Password string
  9. Alias string
  10. }
  11. func (self *Smtp) Send(to []string, subject, body string) error {
  12. m := gomail.NewMessage(/* gomail.SetEncoding(gomail.Base64) */)
  13. m.SetHeader("From", m.FormatAddress(self.Username, self.Alias))
  14. m.SetHeader("To", to...)
  15. m.SetHeader("Subject", subject)
  16. m.SetHeader("text/html", body)
  17. //m.Attach("/tmp/foo.txt",
  18. // gomail.Rename("foo.txt"),
  19. // gomail.SetHeader(map[string][]string{
  20. // "Content-Disposition": []string{
  21. // fmt.Sprintf(`attachment; filename="%s"`, mime.QEncoding.Encode("UTF-8", name)),
  22. // },
  23. // }),
  24. //)
  25. d := gomail.NewDialer(self.Host, self.Port, self.Username, self.Password)
  26. return d.DialAndSend(m)
  27. }