SMTP golang beego 非加密方式代码例子
自行将个人账号和授权码修改。
package main
import (
"fmt"
"github.com/astaxie/beego/utils"
)
// @ test @foxmail.com
func Test163() {
config := `{"username":"@163.com","password":"","host":"smtp.163.com","port":25}`
email := utils.NewEMail(config)
email.To = []string{"@foxmail.com"}
email.From = "@163.com"
email.Subject = "开发项目2"
email.Text = "邮件正文"
email.HTML = "<h1> 您好: hello world</h1>"
err := email.Send()
if err != nil {
fmt.Println(err)
return
}
fmt.Println("finish 163 send mail")
}
func Test163SSL() {
config := `{"username":"@163.com","password":"","host":"smtp.163.com","port":465}`
email := utils.NewEMail(config)
email.To = []string{"@foxmail.com"}
email.From = "@163.com"
email.Subject = "开发项目2"
email.Text = "邮件正文"
email.HTML = "<h1> 您好: hello world</h1>"
err := email.Send()
if err != nil {
fmt.Println(err)
return
}
fmt.Println("finish 163 send mail")
}
// @Test_QQ
func TestQQ() {
config := `{"username":"@qq.com","password":"","host":"smtp.qq.com","port":25}`
email := utils.NewEMail(config)
email.To = []string{"@qq.com"}
email.From = "@qq.com"
email.Subject = "beego-邮件测试"
email.Text = "邮件正文"
email.HTML = "<h1>hello world</h1>"
err := email.Send()
if err != nil {
fmt.Println("show error:", err)
return
}
fmt.Println("finish send email.")
}
func main() {
TestQQ()
// Test139()
// Test163()
// Test163SSL()
}
本文来自博客园,作者:ljymoonlight,转载请注明原文链接:https://www.cnblogs.com/ljymoonlight/p/15084834.html
posted on 2021-07-31 18:01 ljymoonlight 阅读(44) 评论(0) 编辑 收藏 举报