Golang发邮件

简单的发邮件操作

使用gomail这个包

“gopkg.in/gomail.v2”

m := gomail.NewMessage()
	m.SetHeader("From", "yourEamil")
	m.SetHeader("To", targetAddress)
	m.SetHeader("Subject", "your subject")

	m.SetBody("text/html", `html 文本`)

	d := gomail.NewDialer("smtp服务器", port, "账号", "密码")

	// DialAndSend opens a connection to the SMTP server, sends the given emails and
	// closes the connection.
	if err := d.DialAndSend(m); err != nil {
		fmt.Println(err)
		return false
	}
	return true

以上就是一个简单的发邮件过程,可以做邮箱登录,邮箱验证码等等的工作。

你可能感兴趣的:(golang,开发语言,后端)