dongwei6457 2017-09-18 04:05
浏览 197
已采纳

SMTP错误:534在Golang应用中通过gmail发送电子邮件时出现错误

On my golang app I use this snippet to send email from my gmail account:

func send(body string) {
    from := "myaccount@gmail.com"
    pass := "mysupersecretpasswd"
    to := "whoever@whatever.com"

    msg := "From: " + from + "
" +
        "To: " + to + "
" +
        "Subject: Hello there

" +
        body

    err := smtp.SendMail("smtp.gmail.com:587",
        smtp.PlainAuth("", from, pass, "smtp.gmail.com"),
        from, []string{to}, []byte(msg))

    if err != nil {
        log.Printf("smtp error: %s", err)
        return
    }

    log.Print("sent, visit whatever)
}

I get this error instead:

smtp error: 534 5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbud
5.7.14 lxVDnr-tXOckmxXi0fxExY5BKDRczBpGvMCpGWGF97jAI5DlM2oeGMDcIkvBhKT9rJAVnH
5.7.14 WP7zxssynLtkzMb35et-wxJF2AfeBhMA81QqMh2F8fkQRdf9GidA3swFnjfsUl0Pw6fiMT
5.7.14 b3zvEJyD6WAKEWcuxEGJIBTaqCtfDjipQ58cFJweUiKg1_4AJp0fGpC9ufnjBGWqWVKeW9
5.7.14 QVbUstROYK0SzjWXTTvsvZhhG3RjM> Please log in via your web browser and
5.7.14 then try again.
5.7.14  Learn more at
5.7.14  https://support.google.com/mail/answer/78754 61sm6182123wre.44 - gsmtp

I have installed postfix on my localhost. I have also allowed less secure apps to access my account. I have also tried the same code on my VPS, but it does not send emails either.

So what could be wrong? How can I fix it?

  • 写回答

1条回答 默认 最新

  • dongmi1864 2017-09-18 05:15
    关注

    I've copied your gist, replaced from, to and password and it works flawlessly. The only reason why this code is not working is that you are NOT allowing less secure apps in gmail.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥15 Oracle触发器记录修改前后的字段值
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题