email.go 673 B

123456789101112131415161718192021222324252627282930
  1. package utils
  2. import (
  3. "gopkg.in/gomail.v2"
  4. "strings"
  5. )
  6. //发送邮件
  7. func SendEmail(title, content string, touser string)bool {
  8. var arr []string
  9. sub := strings.Index(touser, ";")
  10. if sub >= 0 {
  11. spArr := strings.Split(touser, ";")
  12. for _, v := range spArr {
  13. arr = append(arr, v)
  14. }
  15. }else{
  16. arr = append(arr, touser)
  17. }
  18. m := gomail.NewMessage()
  19. m.SetHeader("From", "317699326@qq.com ")
  20. m.SetHeader("To", arr...)
  21. m.SetHeader("Subject", title+" "+GetRandString(16))
  22. m.SetBody("text/html", content)
  23. d := gomail.NewDialer("smtp.qq.com", 587, "317699326@qq.com", "oqdypwfcvruwcbea")
  24. if err := d.DialAndSend(m); err != nil {
  25. return false
  26. }
  27. return true
  28. }