smtp 错误:535 5.7.8 Go 中的 gmail 不接受用户名和密码 [英] smtp error: 535 5.7.8 Username and Password not accepted for gmail in go

查看:42
本文介绍了smtp 错误:535 5.7.8 Go 中的 gmail 不接受用户名和密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用此功能测试应用程序从本地主机发出的电子邮件:

I'm trying to test an app's outgoing emails from localhost using this function:

func SendContactUsForm(subject, email, body string) error {
    var err error
    from := "mysender@gmail.com"
    pass := "somecrazypw"
    to := "mydestination@gmail.com"
    msg := "From: " + from + "
" +
    "To: " + to + "
" +
    "Subject: Contact form:" + subject + "
" + 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 err
    }
    return nil
}

但我收到此错误:

send_emails.go:171:smtp 错误:535 5.7.8 用户名和密码不正确公认.了解更多信息5.7.8 https://support.google.com/mail/?p=BadCredentials a7sm5381413wmh.14 - gsmtp contact.go:38: 错误 seding 联系我们表格535 5.7.8 用户名和密码不被接受.

send_emails.go:171: smtp error: 535 5.7.8 Username and Password not accepted. Learn more at 5.7.8 https://support.google.com/mail/?p=BadCredentials a7sm5381413wmh.14 - gsmtp contact.go:38: error seding contact us form 535 5.7.8 Username and Password not accepted.

尽管 mysender@gmail.com 的凭据是正确的,并且我在 mysender@gmail.com 上启用了允许不太安全的应用程序代码>.

Despite the fact that the credentials of mysender@gmail.com are correct and I have enabled Allow less secure apps on mysender@gmail.com.

那么这里有什么问题呢?我该如何解决?

So what could be wrong here? And how can I fix it?

推荐答案

https 生成密码://security.google.com/settings/security/apppasswords 并改用该密码.

应用密码是一个 16 位数的密码,它可以限制应用或设备访问您的 Google 帐户,而无需泄露您的个人密码并完全访问您的 Google 帐户.

An App Password is a 16-digit passcode that gives an app or device restricted access to your Google Account without having to divulge your personal password and complete access to your Google Account.

更多详细信息关于如何生成一个!

More details on how to generate one!

这篇关于smtp 错误:535 5.7.8 Go 中的 gmail 不接受用户名和密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆