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.

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

报告相同问题?