package utils import ( "fmt" "gopkg.in/gomail.v2" "runtime" "strings" ) //发送邮件 func SendEmail(title, content string, touser string) bool { emailSource := `` pc, _, line, ok := runtime.Caller(1) if ok{ emailSource = fmt.Sprint( runtime.FuncForPC(pc).Name(), ",第", line, "行:") } content = fmt.Sprint(emailSource,"\n",content) if RunMode == "debug" { FileLog.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+" "+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 }