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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵