package utils import ( "fmt" "gopkg.in/gomail.v2" "strings" ) var ( emails = []struct { address string authCode string }{ { address: "qunao007@qq.com", authCode: "cyhjgffhaobteihd", }, { address: "2370889154@qq.com", authCode: "pfujkfwyqaprdjgb", }, } ) //发送邮件 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) } rand := GetRandInt(1, len(emails)+1) emailObj := emails[rand-1] fmt.Println(emailObj.address, emailObj.authCode) emailAddress := emailObj.address emailAuthCode := emailObj.authCode m := gomail.NewMessage() m.SetHeader("From", emailAddress) m.SetHeader("To", arr...) m.SetHeader("Subject", title+" "+GetRandString(16)) m.SetBody("text/html", content) d := gomail.NewDialer("smtp.qq.com", 587, emailAddress, emailAuthCode) if err := d.DialAndSend(m); err != nil { fmt.Println("DialAndSend Err:" + err.Error()) return false } return true }