跳至内容
U-Mail邮件营销平台FAQ
用户工具
您在这里:
首页
»
smtp接口说明--使用go语言通过smtp协议发送邮件
smtp接口说明--使用go语言通过smtp协议发送邮件
本页面只读。您可以查看源文件,但不能更改它。如果您觉得这是系统错误,请联系管理员。
<code php> package main import ( "fmt" "net/smtp" "strings" ) func SendToMail(user, password, host, to, subject, body, mailtype string) error { hp := strings.Split(host, ":") auth := smtp.PlainAuth("", user, password, hp[0]) var content_type string if mailtype == "html" { content_type = "Content-Type: text/" + mailtype + "; charset=UTF-8" } else { content_type = "Content-Type: text/plain" + "; charset=UTF-8" } msg := []byte("To: " + to + "\r\nFrom: " + user + "\r\nSubject: " + subject + "\r\n" + content_type + "\r\n\r\n" + body) send_to := strings.Split(to, ";") err := smtp.SendMail(host, auth, user, send_to, msg) return err } func main() { user := "U-MAIL创建的发件人地址" password := "U-MAIL后台设置的SMTP密码" host := "smtp.bestedm.org:25" to := "目标地址" subject := "test Golang to sendmail" body := ` <html> <body> <h3> "Test send to email" </h3> </body> </html> ` fmt.Println("send email") err := SendToMail(user, password, host, to, subject, body, "html") if err != nil { fmt.Println("Send mail error!") fmt.Println(err) } else { fmt.Println("Send mail success!") } } </code>
smtp接口说明--使用go语言通过smtp协议发送邮件.txt
· 最后更改: 2017/03/22 03:52 (外部编辑)
页面工具
显示页面
回到顶部