email.go 717 B

123456789101112131415161718192021222324252627282930313233
  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. return false
  10. }
  11. var arr []string
  12. sub := strings.Index(touser, ";")
  13. if sub >= 0 {
  14. spArr := strings.Split(touser, ";")
  15. for _, v := range spArr {
  16. arr = append(arr, v)
  17. }
  18. }else{
  19. arr = append(arr, touser)
  20. }
  21. m := gomail.NewMessage()
  22. m.SetHeader("From", "317699326@qq.com ")
  23. m.SetHeader("To", arr...)
  24. m.SetHeader("Subject", title+" "+GetRandString(16))
  25. m.SetBody("text/html", content)
  26. d := gomail.NewDialer("smtp.qq.com", 587, "317699326@qq.com", "oqdypwfcvruwcbea")
  27. if err := d.DialAndSend(m); err != nil {
  28. return false
  29. }
  30. return true
  31. }