email.go 827 B

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