gpt4 book ai didi

c# - 有没有办法在不选择 'Allow less secure apps' 选项的情况下使用 ASP.NET 通过 Google Apps 帐户发送电子邮件?

转载 作者:太空狗 更新时间:2023-10-30 00:30:30 39 4
gpt4 key购买 nike

我有一个 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 现在需要更高级别的安全和身份验证。然而,仍然可以在没有“允许安全性较低的应用程序”选项的情况下使用它,但您不能使用标准的谷歌用户名和密码。

以下是操作方法(简而言之):

  1. Turn on 2-Step Verification in your gmail or google apps account in “My account / Sign-in & security”,
  2. then (in “My account / Sign-in & security / App passwords”) it is possible to generate a special password for access from other applications (without turned on 2-Step Verification you can not get there)
  3. this created app password (and your google e-mail account as a username) you can then use as your SMTP login.

就这些。

关于c# - 有没有办法在不选择 'Allow less secure apps' 选项的情况下使用 ASP.NET 通过 Google Apps 帐户发送电子邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35699405/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com