smtp设置
// 126
"user": "zetaleee@126.com",
"pass": "DGXZPKILMIIKVRDM",
"host": "smtp.126.com",
"port": "465",
// outlook
"user": "zetaleee@outlook.com",
"pass": "mima",
"host": "smtp-mail.outlook.com",
"port": "587",
库
“gopkg.in/gomail.v2”
实例
m := gomail.NewMessage()
m.SetHeader("From", "alex@example.com")
m.SetHeader("To", "bob@example.com", "cora@example.com")
m.SetAddressHeader("Cc", "dan@example.com", "Dan")
m.SetHeader("Subject", "Hello!")
m.SetBody("text/html", "Hello <b>Bob</b> and <i>Cora</i>!")
m.Attach("/home/Alex/lolcat.jpg")
d := gomail.NewDialer("smtp.example.com", 587, "user", "123456")
// Send the email to Bob, Cora and Dan.
if err := d.DialAndSend(m); err != nil {
panic(err)
}