email.go 1.5 KB

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