2014-05-07 13:06:24 +08:00
|
|
|
package lea
|
|
|
|
|
|
|
|
import (
|
2015-11-13 17:58:41 +08:00
|
|
|
"github.com/revel/revel"
|
2014-05-07 13:06:24 +08:00
|
|
|
"net/smtp"
|
|
|
|
"strings"
|
|
|
|
)
|
2015-11-13 17:58:41 +08:00
|
|
|
|
2014-05-07 13:06:24 +08:00
|
|
|
// 发送邮件
|
|
|
|
var host = "smtp.ym.163.com"
|
|
|
|
var port = "25"
|
|
|
|
var username = "noreply@leanote.com"
|
|
|
|
var password = "---"
|
|
|
|
|
|
|
|
func InitEmail() {
|
2015-11-13 17:58:41 +08:00
|
|
|
config := revel.Config
|
2014-05-07 13:06:24 +08:00
|
|
|
host, _ = config.String("email.host")
|
|
|
|
port, _ = config.String("email.port")
|
|
|
|
username, _ = config.String("email.username")
|
|
|
|
password, _ = config.String("email.password")
|
|
|
|
}
|
|
|
|
|
|
|
|
var bodyTpl = `
|
|
|
|
<html>
|
|
|
|
<body>
|
2014-10-22 16:20:45 +08:00
|
|
|
<div style="width: 600px; margin:auto; border-radius:5px; border: 1px solid #ccc; padding: 20px;">
|
2014-05-07 13:06:24 +08:00
|
|
|
<div>
|
|
|
|
<div>
|
|
|
|
<div style="float:left; height: 40px;">
|
|
|
|
<a href="http://leanote.com" style="font-size: 24px">leanote</a>
|
|
|
|
</div>
|
2014-05-27 11:21:35 +08:00
|
|
|
<div style="float:left; height:40px; line-height:40px;">
|
|
|
|
| <span style="font-size:14px">$title</span>
|
2014-05-07 13:06:24 +08:00
|
|
|
</div>
|
|
|
|
<div style="clear:both"></div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<hr style="border:none;border-top: 1px solid #ccc"/>
|
|
|
|
<div style="margin-top: 20px; font-size: 14px;">
|
|
|
|
$body
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div id="leanoteFooter" style="margin-top: 30px; border-top: 1px solid #ccc">
|
|
|
|
<style>
|
|
|
|
#leanoteFooter {
|
|
|
|
color: #666;
|
|
|
|
font-size: 12px;
|
|
|
|
}
|
|
|
|
#leanoteFooter a {
|
|
|
|
color: #666;
|
|
|
|
font-size: 12px;
|
|
|
|
}
|
|
|
|
</style>
|
2014-05-27 11:21:35 +08:00
|
|
|
<a href="http://leanote.com">leanote</a>, your own cloud note!
|
2014-05-07 13:06:24 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
`
|
2015-11-13 17:58:41 +08:00
|
|
|
|
2014-10-22 16:20:45 +08:00
|
|
|
func SendEmailOld(to, subject, body string) bool {
|
2014-05-07 13:06:24 +08:00
|
|
|
hp := strings.Split(host, ":")
|
|
|
|
auth := smtp.PlainAuth("", username, password, hp[0])
|
2015-11-13 17:58:41 +08:00
|
|
|
|
2014-05-07 13:06:24 +08:00
|
|
|
var content_type string
|
2015-11-13 17:58:41 +08:00
|
|
|
|
2014-05-07 13:06:24 +08:00
|
|
|
mailtype := "html"
|
|
|
|
if mailtype == "html" {
|
2015-11-13 17:58:41 +08:00
|
|
|
content_type = "Content-Type: text/" + mailtype + "; charset=UTF-8"
|
|
|
|
} else {
|
2014-05-07 13:06:24 +08:00
|
|
|
content_type = "Content-Type: text/plain" + "; charset=UTF-8"
|
|
|
|
}
|
2015-11-13 17:58:41 +08:00
|
|
|
|
2014-10-22 16:20:45 +08:00
|
|
|
//body = strings.Replace(bodyTpl, "$body", body, 1)
|
|
|
|
//body = strings.Replace(body, "$title", title, 1)
|
2014-05-07 13:06:24 +08:00
|
|
|
|
2015-11-13 17:58:41 +08:00
|
|
|
msg := []byte("To: " + to + "\r\nFrom: " + username + "<" + username + ">\r\nSubject: " + subject + "\r\n" + content_type + "\r\n\r\n" + body)
|
2014-05-07 13:06:24 +08:00
|
|
|
send_to := strings.Split(to, ";")
|
|
|
|
err := smtp.SendMail(host+":"+port, auth, username, send_to, msg)
|
2015-11-13 17:58:41 +08:00
|
|
|
|
2014-05-07 13:06:24 +08:00
|
|
|
if err != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2014-10-22 16:20:45 +08:00
|
|
|
func SendToLeanoteOld(subject, title, body string) {
|
2014-05-07 13:06:24 +08:00
|
|
|
to := "leanote@leanote.com"
|
2015-11-13 17:58:41 +08:00
|
|
|
SendEmailOld(to, subject, body)
|
|
|
|
}
|