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

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 数据库原理及应用上机练习题
  • ¥30 征集Python提取PDF文字属性的代码
  • ¥15 如何联系真正的开发者而非公司
  • ¥15 有偿求苍穹外卖环境配置
  • ¥15 代码在keil5里变成了这样怎么办啊,文件图像也变了,
  • ¥20 Ue4.26打包win64bit报错,如何解决?(语言-c++)
  • ¥15 clousx6整点报时指令怎么写
  • ¥30 远程帮我安装软件及库文件
  • ¥15 关于#自动化#的问题:如何通过电脑控制多相机同步拍照或摄影(相机或者摄影模组数量大于60),并将所有采集的照片或视频以一定编码规则存放至规定电脑文件夹内
  • ¥20 (求远程解决)深信服vpn-2050这台设备如何配置才能成功联网?