123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- package utils
- import (
- "crypto/tls"
- "strings"
- "gopkg.in/gomail.v2"
- )
- // 发送邮件
- func SendEmail(title, content string, touser 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", "")
- m.SetHeader("To", arr...)
- m.SetHeader("Subject", title+" "+GetRandString(16))
- m.SetBody("text/html", content)
- d := gomail.NewDialer("smtp.qq.com", 587, "", "")
- if err := d.DialAndSend(m); err != nil {
- return false
- }
- return true
- }
- // 发送邮件
- func SendEmailByDw(title, content string, touser string) (result bool, err error) {
- var arr []string
- sub := strings.Index(touser, ";")
- if sub >= 0 {
- spArr := strings.Split(touser, ";")
- arr = append(arr, spArr...)
- // for _, v := range spArr {
- // arr = append(arr, v)
- // }
- } else {
- arr = append(arr, touser)
- }
- m := gomail.NewMessage()
- if RunMode == "debug" {
- m.SetHeader("From", "564693862@qq.com")
- } else {
- m.SetHeader("From", "lvan@dwqh88.com")
- }
- m.SetHeader("To", arr...)
- m.SetHeader("Subject", title)
- m.SetBody("text/html", content)
- var d *gomail.Dialer
- if RunMode == "debug" {
- d = gomail.NewDialer("smtp.qq.com", 587, "564693862@qq.com", "xvjmiuepszmmbdhc")
- } else {
- d = gomail.NewDialer("smtp.dwqh88.com", 25, "lvan@dwqh88.com", "Dwqh20248888")
- }
- // d := gomail.NewDialer("mail.dwqh88.com", 465, "lvan@dwqh88.com", "Dwqh20248888")
- // d := gomail.NewDialer("smtp.qq.com", 587, "564693862@qq.com", "xvjmiuepszmmbdhc")
- d.TLSConfig = &tls.Config{InsecureSkipVerify: true}
- if err := d.DialAndSend(m); err != nil {
- result = false
- return result, err
- }
- result = true
- return
- }
|