email.go 777 B

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