Gomail is a simple and efficient package to send emails. It is well tested and documented.
译文:Gomail是一个简单高效的电子邮件发送包。它经过了良好的测试和记录。
文档
安装
go get gopkg.in/gomail.v2
示例
package main
import (
"gopkg.in/gomail.v2"
)
func main() {
// 邮件内容
m := gomail.NewMessage()
m.SetHeader("From", )
m.SetHeader("To", )
m.SetHeader("Subject", "邮件标题")
m.SetBody("text/html", "<h2>邮件内容</h2>")
// 邮件服务器账号密码
// func NewDialer(host string, port int, username, password string) *Dialer
d := gomail.NewDialer(
"smtp.163.com",
25,
,
"password",
)
// 发送邮件
d.DialAndSend(m)
}