1
我有一个应该通过Gmail发送电子邮件的联系页面。无法通过Gmail发送电子邮件
下面是代码:
func sendContactEmail(subject string, email string, message string) {
auth := smtp.PlainAuth(
"contact form submit",
"[email protected]",
"mypassword",
"smtp.gmail.com",
)
// Connect to the server, authenticate, set the sender and recipient,
// and send the email all in one step.
body := subject + "\r\n" + email +"\r\n" + message
msg := "Subject: Contact us" + "\r\n\r\n" + body + "\r\n"
err := smtp.SendMail(
"smtp.gmail.com:587",
auth,
"[email protected]",
[]string{"[email protected]"},
[]byte(msg),
)
if err != nil {
log.Fatal(err)
}
return
}
func ContactPOST(w http.ResponseWriter, r *http.Request) {
// Get form values
subject := r.FormValue("subject")
email := r.FormValue("email")
message := r.FormValue("message")
go sendContactEmail(subject, email, message)
// Display the thank you page
v := view.New(r)
v.Name = "contact/thanks"
v.Render(w)
return
}
这里是错误消息:
contact.go:41: 534 5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbti
5.7.14 HcGWI2H6QjVTNjHS4X49PcBxQQGNhL9TKnzdQxqYgeUXkWxpHj90RSAaIbI-ySSrKFTV4q
5.7.14 IVZeXExVeqhuZnPhtvUtx9p5Ly7gBxwFLzrrgWcm4NZ3_vhDOWiH-uDsPb5eoa4rbYCepd
5.7.14 PlD9kBBz1dAlhdRDJ7mwqsUMJUV7MHTgNWqTcT_R89Uq9oYtwurtmGAuv2YAkPTCBtPwXq
5.7.14 9ooL5edn_sTI6WJW72sK2ilMCIUB0> 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 63sm17219759wmg.2 - gsmtp
奇怪的是,表格工作正常,当我自己的计算机上发送电子邮件,和只有在显示thank you
页面后http服务器刚刚死亡的VPS上部署应用程序时才会发生错误。
我也试过在没有goroutine的情况下调用sendContactEmail
,但仍然得到相同的错误。
我很感激你的提示来解决这个问题。
那么,我使用个人帐户(而不是G套件),我设置了“访问不太安全的应用程序”。 – graco
更新:按照谷歌的故障排除链接建议访问此页面'https:// accounts.google.com/DisplayUnlockCaptcha'解决了这个问题。请更新您的答案,我会接受它。 – graco