beego郵件發送
以QQ郵箱為例,其他郵箱大同小異
- 設定郵箱-選擇 IMAP/SMTP 服務,點選開啟服務
- 導包:找不到包可以手動下載下傳 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郵箱的密碼,通過上面生成授權碼。