天天看点

beego邮件发送

beego邮件发送

以QQ邮箱为例,其他邮箱大同小异

  • 设置邮箱-选择 IMAP/SMTP 服务,点击开启服务
    beego邮件发送
  • 导包:找不到包可以手动下载 https://github.com/astaxie/beego/tree/master
import (
	"github.com/astaxie/beego/utils"
)
           
email := "[email protected]"  //接收者邮箱
	emailConfig := `{"username":"[email protected]","password":"abcdefg","host":"smtp.qq.com","port":587}`
	emailConn := utils.NewEMail(emailConfig)
	emailConn.From = "[email protected]"   //发送者邮箱
	emailConn.To = []string{email}
	emailConn.Subject = "邮件标题"
	emailConn.Text = "邮件内容"
	emailConn.Send()
           
  • username为发送者的邮箱,注意:password不是QQ邮箱的密码,通过上面生成授权码。