email.go 434 B

12345678910111213141516171819
  1. package dao
  2. import (
  3. "go-common/library/log"
  4. "gopkg.in/gomail.v2"
  5. )
  6. func (d *Dao) SendEmail(subject string, to string, body string) (err error) {
  7. msg := gomail.NewMessage()
  8. msg.SetHeader("From", d.c.Mail.Username)
  9. msg.SetHeader("To", to)
  10. msg.SetHeader("Subject", subject)
  11. msg.SetBody("text/plain", body)
  12. if err = d.email.DialAndSend(msg); err != nil {
  13. log.Error("s.email.DialAndSend error(%v)", err)
  14. return
  15. }
  16. return
  17. }