12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- package services
- import (
- "gopkg.in/gomail.v2"
- "hongze/hongze_yb_en_api/services/alarm_msg"
- "strings"
- )
- // SendEmailCode 发送邮件
- func SendEmailCode(name, email string) (err error, errMsg string) {
- defer func() {
- if err != nil {
- go alarm_msg.SendAlarmMsg("阿里云群发英文研报邮件失败, Err: "+err.Error(), 3)
- }
- }()
- // 请求阿里云接口批量推送
- aliEmail := new(AliyunEmail)
- _, e := aliEmail.SendEmailCode(name, email)
- if e != nil {
- err = e
- return
- }
- return
- }
- //发送邮件
- 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
- }
|