package lea import ( "github.com/revel/revel" "net/smtp" "strings" ) // 发送邮件 var host = "smtp.ym.163.com" var port = "25" var username = "noreply@leanote.com" var password = "---" func InitEmail() { config := revel.Config host, _ = config.String("email.host") port, _ = config.String("email.port") username, _ = config.String("email.username") password, _ = config.String("email.password") } var bodyTpl = `
leanote
  |  $title

$body
leanote, your own cloud note!
` func SendEmailOld(to, subject, body string) bool { hp := strings.Split(host, ":") auth := smtp.PlainAuth("", username, password, hp[0]) var content_type string mailtype := "html" if mailtype == "html" { content_type = "Content-Type: text/" + mailtype + "; charset=UTF-8" } else { content_type = "Content-Type: text/plain" + "; charset=UTF-8" } //body = strings.Replace(bodyTpl, "$body", body, 1) //body = strings.Replace(body, "$title", title, 1) msg := []byte("To: " + to + "\r\nFrom: " + username + "<" + username + ">\r\nSubject: " + subject + "\r\n" + content_type + "\r\n\r\n" + body) send_to := strings.Split(to, ";") err := smtp.SendMail(host+":"+port, auth, username, send_to, msg) if err != nil { Log(err) return false } return true } func SendToLeanoteOld(subject, title, body string) { to := "leanote@leanote.com" SendEmailOld(to, subject, body) }