email.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package utils
  2. import (
  3. "gopkg.in/gomail.v2"
  4. "strings"
  5. )
  6. func SendEmail(title, content string, touser string) bool {
  7. var arr []string
  8. sub := strings.Index(touser, ";")
  9. if sub >= 0 {
  10. spArr := strings.Split(touser, ";")
  11. for _, v := range spArr {
  12. arr = append(arr, v)
  13. }
  14. } else {
  15. arr = append(arr, touser)
  16. }
  17. m := gomail.NewMessage()
  18. m.SetHeader("From", "317699326@qq.com ")
  19. m.SetHeader("To", arr...)
  20. m.SetHeader("Subject", title+" "+GetRandString(16))
  21. m.SetBody("text/html", content)
  22. d := gomail.NewDialer("smtp.qq.com", 587, "317699326@qq.com", "oqdypwfcvruwcbea")
  23. if err := d.DialAndSend(m); err != nil {
  24. return false
  25. }
  26. return true
  27. }
  28. func SendEmailByHz(title, content string, touser string) (result bool, err error) {
  29. var arr []string
  30. sub := strings.Index(touser, ";")
  31. if sub >= 0 {
  32. spArr := strings.Split(touser, ";")
  33. for _, v := range spArr {
  34. arr = append(arr, v)
  35. }
  36. } else {
  37. arr = append(arr, touser)
  38. }
  39. m := gomail.NewMessage()
  40. m.SetHeader("From", "public@hzinsights.com")
  41. m.SetHeader("To", arr...)
  42. m.SetHeader("Subject", title)
  43. m.SetBody("text/html", content)
  44. d := gomail.NewDialer("smtp.mxhichina.com", 465, "public@hzinsights.com", "Hzinsights2018")
  45. if err := d.DialAndSend(m); err != nil {
  46. result = false
  47. return result, err
  48. }
  49. result = true
  50. return
  51. }