email.go 1.3 KB

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