golang发送邮件

参考github第三方发送邮件框架:

https://github.com/jordan-wright/email

 

package main

import (
   "github.com/jordan-wright/email"
   "golang.org/x/text/encoding/simplifiedchinese"
   "net/smtp"
   "net/textproto"
)
func main() {
   e := &email.Email {
      To: []string{"[email protected]"},
      From: "[email protected]",
      Subject: "Email Send Test 1800",
      Text: []byte("Text Body is, of course, supported!"),
      HTML: []byte("

This a test email

"), Headers: textproto.MIMEHeader{}, } err := e.Send("smtp.exmail.qq.com:587", smtp.PlainAuth("", "[email protected]", "password", "smtp.exmail.qq.com")) if err !=nil { panic(err) } print("邮件发送成功") }

如果是腾讯企业邮箱,服务器是smtp.exmail.qq.com:465,password更改为邮箱授权码
                                    服务器是smtp.exmail.qq.com:587,password更改为邮箱密码

你可能感兴趣的:(go)