Home > Article > Backend Development > Detailed explanation of sending emails in golang (qq mailbox)
The following tutorial column of golang will introduce to you the method of sending emails (qq mailbox) in golang. I hope it will be helpful to friends in need!
golang sends email (qq mailbox)
Golang sends email function, today we introduce golang to send qq email, I believe everyone has a qq mailbox, which is relatively convenient to operate. It is even simpler to use golang to send emails. I believe everyone can get started and learn it after reading this.
Sending emails through encoding means actually calling the interface provided by qq mailbox to send emails. Before writing this function, we need to get the authorization code of the POP3/SMTP service of qq mailbox
package mainimport ( "fmt" "gopkg.in/gomail.v2")func main() { m := gomail.NewMessage() //发送人 m.SetHeader("From", "xxx@qq.com") //接收人 m.SetHeader("To", "xxx@qq.com") //抄送人 //m.SetAddressHeader("Cc", "xxx@qq.com", "xiaozhujiao") //主题 m.SetHeader("Subject", "小佩奇") //内容 m.SetBody("text/html", "<h1>新年快乐</h1>") //附件 //m.Attach("./myIpPic.png") //拿到token,并进行连接,第4个参数是填授权码 d := gomail.NewDialer("smtp.qq.com", 587, "xxx@qq.com", "xxxxxx") // 发送邮件 if err := d.DialAndSend(m); err != nil { fmt.Printf("DialAndSend err %v:", err) panic(err) } fmt.Printf("send mail success\n")}
The above is the detailed content of Detailed explanation of sending emails in golang (qq mailbox). For more information, please follow other related articles on the PHP Chinese website!