SMTP golang beego 非加密方式程式碼例子
阿新 • • 發佈:2021-07-31
自行將個人賬號和授權碼修改。
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() }