【发布时间】:2021-05-22 21:40:57
【问题描述】:
我在尝试使用 Google 的 SMTP 服务器时收到以下错误。
535 5.7.8 Username and Password not accepted. Learn more at 5.7.8 https://support.google.com/mail/?p=BadCredentials fa15sm2375541pjb.40 - gsmtp
这是我的代码:
// Sender data.
from := req.FormValue("email")
//password := "xxxx" //<- log in password fails
password := "xxxx" // <- app password fails
// Receiver email address.
to := []string{
"myemail@gmail.com",
}
// smtp server configuration.
smtpHost := "smtp.gmail.com"
smtpPort := "587"
msg := req.FormValue("name") + "\n" + req.FormValue("message")
message := []byte(msg)
auth := smtp.PlainAuth("", from, password, smtpHost)
err := smtp.SendMail(smtpHost+":"+smtpPort, auth, from, to, message)
if err != nil {
tmp.Message = "Message not sent: " + err.Error()
htmlTags["contact"] = tmp
err = tmpl.ExecuteTemplate(w, "send_failure", htmlTags["contact"])
} else {
tmp.Message = "Message sent"
htmlTags["contact"] = tmp
err = tmpl.ExecuteTemplate(w, "send_success", htmlTags["contact"])
}
} else {
tmp.Message = "You message has not been sent. Cookies are required to send messages."
htmlTags["contact"] = tmp
err = tmpl.ExecuteTemplate(w, "send_failure", htmlTags["contact"])
}
该帐户启用了 2FA 并使用了应用密码。
允许安全性较低的应用:开启
发送代码也存在于带有自签名证书的服务器上,出现以下错误:
Certificate - missing
This site is missing a valid, trusted certificate (net::ERR_CERT_AUTHORITY_INVALID).
【问题讨论】:
-
请编辑您的问题并为您的代码语言添加标签。