![](/img/trans.png)
[英]Send an email without having to enable less secure apps in google
[英]Is there a way to use ASP.NET to send email through a Google Apps account without selecting the 'Allow less secure apps' option?
我有一个试图用来发送电子邮件的 ASP.NET Web API。 我在使用 smtp.gmail.com 和 587 时遇到了身份验证问题。我看到几个链接说要在我的 Google Apps 帐户上切换“允许不太安全的应用程序”选项,但我不想向所有者解释为什么他们需要选择这种听起来可疑的设置。
有没有办法在 ASP.NET 中打包 Google 喜欢的电子邮件请求,还是我必须选择“允许不太安全的应用程序”选项?
这是我使用的 Google 不喜欢的代码。
using (var client = new SmtpClient("smtp.googlemail.com", 587))
{
client.Credentials =
new System.Net.NetworkCredential("address@yourdomain.com", "yourpassword");
client.EnableSsl = true;
var msg = new MailMessage("address@yourdomain.com", "toaddress@anotherdomain.com");
msg.Body = "[YOUR EMAIL BODY HERE]";
msg.Subject = "[Message Subject]";
client.Send(msg);
}
谷歌前段时间(一两年前)改变了使用其 SMTP 服务器的可能性。 Google 现在需要更高级别的安全性和身份验证。 但是,仍然有可能在没有“允许不太安全的应用程序”选项的情况下使用它,但您不能使用标准的谷歌用户名和密码。
这是如何做到的(简而言之):
- 在“我的帐户/登录和安全”中打开您的 gmail 或 google 应用程序帐户中的两步验证,
- 然后(在“我的帐户/登录和安全性/应用程序密码”中)可以生成一个特殊密码以供其他应用程序访问(如果没有打开两步验证,您将无法访问)
- 这个创建的应用程序密码(和您的谷歌电子邮件帐户作为用户名)然后您可以用作您的 SMTP 登录。
就这样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.