|
@@ -1,7 +1,9 @@
|
|
|
package utils
|
|
|
|
|
|
import (
|
|
|
+ "fmt"
|
|
|
"gopkg.in/gomail.v2"
|
|
|
+ "mime"
|
|
|
"strings"
|
|
|
)
|
|
|
|
|
@@ -86,3 +88,40 @@ func SendEmailHaveFile(title, content string, fileName, touser string) bool {
|
|
|
}
|
|
|
return true
|
|
|
}
|
|
|
+
|
|
|
+//发送邮件
|
|
|
+func SendEmailByHongze(title, content string, touser, attachPath, attachName string) bool {
|
|
|
+ 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+" "+GetRandStringNoSpecialChar(8))
|
|
|
+ m.SetBody("text/html", content)
|
|
|
+
|
|
|
+ //body := new(bytes.Buffer)
|
|
|
+ if attachPath != "" {
|
|
|
+ m.Attach(attachPath,
|
|
|
+ gomail.Rename(attachName),
|
|
|
+ gomail.SetHeader(map[string][]string{
|
|
|
+ "Content-Disposition": []string{
|
|
|
+ fmt.Sprintf(`attachment; filename="%s"`, mime.QEncoding.Encode("UTF-8", attachName)),
|
|
|
+ },
|
|
|
+ }))
|
|
|
+ }
|
|
|
+ d := gomail.NewDialer("smtp.mxhichina.com", 465, "public@hzinsights.com", "Hzinsights2018")
|
|
|
+ if err := d.DialAndSend(m); err != nil {
|
|
|
+ fmt.Println("send err:", err.Error())
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ return true
|
|
|
+}
|