email.go 778 B

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