email.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. package email
  2. import (
  3. "go-common/library/log"
  4. "os"
  5. "go-common/app/job/main/up/conf"
  6. "gopkg.in/gomail.v2"
  7. )
  8. //SendMail send the email.
  9. func (d *Dao) SendMail(body string, subject string, send []string) (err error) {
  10. log.Info("send mail send:%v", send)
  11. msg := gomail.NewMessage()
  12. msg.SetHeader("From", conf.Conf.MailConf.Username)
  13. msg.SetHeader("To", send...)
  14. msg.SetHeader("Subject", subject)
  15. msg.SetBody("text/html", body, gomail.SetPartEncoding(gomail.Base64))
  16. if err = d.email.DialAndSend(msg); err != nil {
  17. log.Error("s.email.DialAndSend error(%v)", err)
  18. return
  19. }
  20. return
  21. }
  22. //SendMailAttach send the email.
  23. func (d *Dao) SendMailAttach(filename string, subject string, send []string) (err error) {
  24. msg := gomail.NewMessage()
  25. msg.SetHeader("From", conf.Conf.MailConf.Username)
  26. msg.SetHeader("To", send...)
  27. msg.SetHeader("Subject", subject)
  28. msg.Attach(filename)
  29. if err = d.email.DialAndSend(msg); err != nil {
  30. log.Error("s.email.DialAndSend error(%v)", err)
  31. return
  32. }
  33. err = os.Remove(filename)
  34. return
  35. }