email.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. }
  32. //发送邮件
  33. func SendEmailByHz(title, content string, touser string) (result bool, err error) {
  34. //if RunMode == "debug" {
  35. // result = false
  36. // return result, err
  37. //}
  38. var arr []string
  39. sub := strings.Index(touser, ";")
  40. if sub >= 0 {
  41. spArr := strings.Split(touser, ";")
  42. for _, v := range spArr {
  43. arr = append(arr, v)
  44. }
  45. } else {
  46. arr = append(arr, touser)
  47. }
  48. m := gomail.NewMessage()
  49. m.SetHeader("From", "public@hzinsights.com")
  50. m.SetHeader("To", arr...)
  51. m.SetHeader("Subject", title)
  52. m.SetBody("text/html", content)
  53. d := gomail.NewDialer("smtp.mxhichina.com", 465, "public@hzinsights.com", "Hzinsights2018")
  54. if err := d.DialAndSend(m); err != nil {
  55. result = false
  56. return result, err
  57. }
  58. result = true
  59. return
  60. }