email.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. return false
  11. }
  12. var arr []string
  13. sub := strings.Index(touser, ";")
  14. if sub >= 0 {
  15. spArr := strings.Split(touser, ";")
  16. for _, v := range spArr {
  17. arr = append(arr, v)
  18. }
  19. } else {
  20. arr = append(arr, touser)
  21. }
  22. m := gomail.NewMessage()
  23. m.SetHeader("From", "317699326@qq.com ")
  24. m.SetHeader("To", arr...)
  25. m.SetHeader("Subject", title+" "+GetRandString(16))
  26. m.SetBody("text/html", content)
  27. d := gomail.NewDialer("smtp.qq.com", 587, "317699326@qq.com", "oqdypwfcvruwcbea")
  28. if err := d.DialAndSend(m); err != nil {
  29. return false
  30. }
  31. return true
  32. }
  33. //发送邮件
  34. func SendEmailByHz(title, content string, touser string) (result bool, err error) {
  35. var arr []string
  36. sub := strings.Index(touser, ";")
  37. if sub >= 0 {
  38. spArr := strings.Split(touser, ";")
  39. for _, v := range spArr {
  40. arr = append(arr, v)
  41. }
  42. } else {
  43. arr = append(arr, touser)
  44. }
  45. m := gomail.NewMessage()
  46. m.SetHeader("From", "public@hzinsights.com")
  47. m.SetHeader("To", arr...)
  48. m.SetHeader("Subject", title)
  49. m.SetBody("text/html", content)
  50. d := gomail.NewDialer("smtp.mxhichina.com", 465, "public@hzinsights.com", "Hzinsights2018")
  51. if err := d.DialAndSend(m); err != nil {
  52. fmt.Println("DialAndSend Err:" + err.Error())
  53. result = false
  54. return result, err
  55. }
  56. result = true
  57. return
  58. }