參考:https://medium.com/glottery/sending-emails-with-go-golang-and-gmail-39bc20423cf0
需要配置google 的安全策略,配置方法參考上述連接。
測(cè)試代碼
package main
import (
"fmt"
"net/smtp"
)
func main() {
from := "xxxxx"
password := "xxxx"
to := []string{
"simoncj90@gmail.com",
}
message := []byte("test")
auth := smtp.PlainAuth("", from, password, "smtp.gmail.com")
err := smtp.SendMail("smtp.gmail.com:587", auth, from, to, message)
if err != nil {
return
}
fmt.Println("Email Sent!")
}