123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- package services
- import (
- "fmt"
- "gopkg.in/gomail.v2"
- "hongze/hongze_yb/global"
- "hongze/hongze_yb/utils"
- "strings"
- )
- //发送邮件
- func SendEmail(title, content string, touser string) bool {
- if global.CONFIG.Serve.RunMode == "debug" {
- global.LOG.Info(fmt.Sprint(title, ";", content))
- return false
- }
- var arr []string
- sub := strings.Index(touser, ";")
- if sub >= 0 {
- spArr := strings.Split(touser, ";")
- for _, v := range spArr {
- arr = append(arr, v)
- }
- } else {
- arr = append(arr, touser)
- }
- m := gomail.NewMessage()
- m.SetHeader("From", "317699326@qq.com ")
- m.SetHeader("To", arr...)
- m.SetHeader("Subject", title+" "+utils.GetRandString(16))
- m.SetBody("text/html", content)
- d := gomail.NewDialer("smtp.qq.com", 587, "317699326@qq.com", "oqdypwfcvruwcbea")
- if err := d.DialAndSend(m); err != nil {
- return false
- }
- return true
- }
- //发送邮件
- func SendEmailByHz(title, content string, touser string) (result bool, err error) {
- var arr []string
- sub := strings.Index(touser, ";")
- if sub >= 0 {
- spArr := strings.Split(touser, ";")
- for _, v := range spArr {
- arr = append(arr, v)
- }
- } else {
- arr = append(arr, touser)
- }
- m := gomail.NewMessage()
- m.SetHeader("From", "public@hzinsights.com")
- m.SetHeader("To", arr...)
- m.SetHeader("Subject", title)
- m.SetBody("text/html", content)
- d := gomail.NewDialer("smtp.mxhichina.com", 465, "public@hzinsights.com", "Hzinsights2018")
- if err := d.DialAndSend(m); err != nil {
- result = false
- return result, err
- }
- result = true
- return
- }
|