【发布时间】:2021-01-11 05:31:17
【问题描述】:
我正在为我的新网站构建一个联系表单,并希望通过 Google 的 SMTP 中继服务器 (smtp-relay.gmail.com) 发送邮件,因为我想设置一个“虚拟”、“无回复”地址发送邮件。此外,我尝试使用我自己的该帐户的实际 Gmail 凭据通过常规 SMTP 服务器 (smtp.gmail.com) 发送它,但它作为不安全的应用程序被阻止。我宁愿不打开“Less secure app access”选项(这对我来说并不是一个真正的选项,因为我在这个帐户上使用 2FA),所以这看起来像到达那里的最佳方式 - 如果我可以让它工作。
域的邮件托管在 G Suite 中,我已按照支持文章 SMTP relay: Route outgoing non-Gmail messages through Google 中的说明为我的域配置了 Google Admin Console 中的 SMTP 中继服务。我使用网站的公共静态 IP 地址以及 Web 服务器所在的防火墙的静态 IP 地址配置了中继。我将中继配置为接受来自我的域的邮件,以允许实际上没有邮箱的“虚拟”地址,并将其设置为需要 SMTP 身份验证和 TLS 加密:
我已通过我的域名注册商为 MX、SPF 和 DKIM 设置了 DNS 记录。
我已等待超过 24 小时让更改生效(根据在 Google 管理控制台中进行更改时的通知)
我什至为我的网站设置了一个应用程序密码,用于我的域电子邮件地址:
我在 IIS 上使用 ASP.NET (VB) 网站。我的发送代码如下所示:
Dim NewContact As New System.Net.Mail.MailMessage()
With NewContactMessage
.From = New System.Net.Mail.MailAddress("no-reply@mydomain.com")
.To.Add("myaddress@mydomain.com")
.Subject= "TEST MESSAGE"
.IsBodyHtml= True
.BodyEncoding = System.Text.Encoding.UTF8
.Body = "This is a test."
.Priority = System.Net.Mail.MailPriority.Normal
End With
Dim Server As New System.Net.Mail.SmtpClient()
With Server
.Port= 587
.Host= "smtp-relay.gmail.com"
.EnableSsl= True
.Send(NewContactMessage)
End With
但是,当我尝试提交我的联系表单时,我收到一个错误,Mailbox unavailable. The server response was: 5.7.1 Invalid credentials for relay [X.X.X.X]. The IP address you've:
看起来确实应该有更多实际错误消息,但它显然在途中被截断了。
我已尝试在 SmtpClient 块中提供凭据:
With Server
.Credentials = New System.Net.NetworkCredential("myaddress@mydomain.com", "my_app_password")
.Port= 587
.Host= "smtp-relay.gmail.com"
.EnableSsl= True
.Send(NewContactMessage)
End With
在这种情况下,我得到一个不同的错误:The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Authentication Required. Learn more at。 (如果我将凭据与“默认”Gmail SMTP 服务器 (smtp.gmail.com) 一起使用,我会收到同样的错误。)
根据审核日志,我的所有配置设置更改似乎都已完成。 似乎一切都是正确的,但我错过了什么?
【问题讨论】:
-
我已经阅读了建议的重复问题,虽然它有许多可能的解决方案,但它不包括 Send mail via google app with smtp relay 中真正解决我的问题的一个解决方案 - 关闭 Require SMTP Authentication 选项。虽然该问题没有公认的答案,但它实际上是比提议的更合适的“重复”。将其作为对提议的副本的答案发布会更好吗,即使该答案已经被接受?