美文网首页
gmail 通过SMTP 发送邮件

gmail 通过SMTP 发送邮件

作者: csimonj | 来源:发表于2020-01-07 18:25 被阅读0次

参考: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!")
}

相关文章

网友评论

      本文标题:gmail 通过SMTP 发送邮件

      本文链接:https://www.haomeiwen.com/subject/hxrdactx.html