SMTP错误:535 5.7.8 Go中的gmail不接受用户名和密码 [英] smtp error: 535 5.7.8 Username and Password not accepted for gmail in go
问题描述
我正在尝试使用此功能测试来自本地主机的应用的传出电子邮件:
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 + "\n" +
"To: " + to + "\n" +
"Subject: Contact form:" + subject + "\n" + 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
的凭据是正确的,并且我启用了 Allow安全性较低的应用程序
在 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.
更多详细说明如何生成一个!
这篇关于SMTP错误:535 5.7.8 Go中的gmail不接受用户名和密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!