参考:https://medium.com/glottery/sending-emails-with-go-golang-and-gmail-39bc20423cf0
需要配置google 的安全策略,配置方法参考上述连接。
测试代码
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!")
}