email.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package utils
  2. import (
  3. "strings"
  4. "gopkg.in/gomail.v2"
  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 SendEmailByDw(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. arr = append(arr, spArr...)
  36. // for _, v := range spArr {
  37. // arr = append(arr, v)
  38. // }
  39. } else {
  40. arr = append(arr, touser)
  41. }
  42. m := gomail.NewMessage()
  43. // m.SetHeader("From", "lvan@dwqh88.com")
  44. m.SetHeader("From", "564693862@qq.com")
  45. m.SetHeader("To", arr...)
  46. m.SetHeader("Subject", title)
  47. m.SetBody("text/html", content)
  48. d := gomail.NewDialer("smtp.qq.com", 587, "564693862@qq.com", "izytoolbgbirbbhb")
  49. // d := gomail.NewDialer("mail.dwqh88.com", 465, "lvan@dwqh88.com", "Dwqh20248888")
  50. if err := d.DialAndSend(m); err != nil {
  51. result = false
  52. return result, err
  53. }
  54. result = true
  55. return
  56. }