go自带了一个可以发邮件的包,但是感觉不好用,不如用第三方封装好的包:
首先安装一个第三方包:
go get gopkg.in/gomail.v2
package main
import "gopkg.in/gomail.v2"
func main() {
m := gomail.NewMessage()
m.SetHeader("From", "1543323033@qq.com")
m.SetHeader("To", "13435515713@163.com", "edison939878@gmail.com")
m.SetHeader("Subject", "Hello!")
m.SetBody("text/html", "this is a test email for you, enjoy!")
d := gomail.NewDialer("smtp.qq.com", 465, "1543323033@qq.com", "你的密码")
if err := d.DialAndSend(m); err != nil {
panic(err)
}
}
网友评论