Golang's method of sending and receiving emails: 1. The sender's right-click must open the stmt and pop3 channels; 2. After opening, obtain the authorization code of the account, the code is [m.SetAddressHeader("Cc", "dan @example.com", "Dan")].
Golang’s method of sending and receiving emails:
I won’t introduce the sending and receiving of emails, just go to the code
package main import ( "gopkg.in/gomail.v2" ) func main() { m := gomail.NewMessage() m.SetHeader("From", "xxxxx@qq.com") m.SetHeader("To", "yyyyy@qq.com") //m.SetAddressHeader("Cc", "dan@example.com", "Dan") m.SetHeader("Subject", "Hello!") m.SetBody("text/html", "Hello <b>Bob</b> and <i>Cora</i>!") //m.Attach("/home/Alex/lolcat.jpg") d := gomail.NewDialer("smtp.qq.com", 587, "xxxxx@qq.com", "okbnsnqptzjzfigd") // Send the email to Bob, Cora and Dan. if err := d.DialAndSend(m); err != nil { panic(err) } }
The only pitfall is the password
After replacing the xxxx and yyyyy accounts in the code with the sender and receiver, the arrow points not to your login password, but to the authorization code
Using a custom client to send emails requires the following two elements:
1. The sender’s right-click must open stmt and pop3 channels, with qq mailbox as the For example, log in to qq mailbox->Settings-Account->Enable pop3 and stmt services
2. After opening, you will get the authorization code of the account. You don’t need to remember it, it can be generated temporarily. (But it seems to be If it is effective for a long time, it is recommended to record it~)
##Related learning recommendations:
The above is the detailed content of How to send and receive emails in golang?. For more information, please follow other related articles on the PHP Chinese website!