有没有一种方法可以使用ASP.NET通过Google Apps帐户发送电子邮件,而无需选择“允许不太安全的应用程序"选项? [英] Is there a way to use ASP.NET to send email through a Google Apps account without selecting the 'Allow less secure apps' option?

查看:83
本文介绍了有没有一种方法可以使用ASP.NET通过Google Apps帐户发送电子邮件,而无需选择“允许不太安全的应用程序"选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ASP.NET Web API,我正尝试使用它来发送电子邮件.我使用smtp.gmail.com和587遇到身份验证问题.我看到几个链接说,要在我的Google Apps帐户上切换允许安全程度较低的应用程序"选项,但我不想向所有者解释为什么他们需要选择这种可疑的设置.

I have an ASP.NET web API that I'm trying to use to send an email. I'm getting authentication issues using smtp.gmail.com and 587. I've seen several links saying to toggle the 'Allow less secure apps' option on my Google Apps account, but I'd rather not have to explain to the owners why they need to pick this dubious-sounding setting.

是否可以将Google希望在ASP.NET中打包电子邮件请求,还是必须选择允许安全程度较低的应用程序"选项?

Is there a way to package an email request in ASP.NET that Google will like, or will I have to select the 'Allow less secure apps' option?

这是我不喜欢Google使用的代码.

This is the code I'm using that Google doesn't like.

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);
}

推荐答案

Google在一段时间(一两年前)更改了使用其SMTP服务器的可能性. Google现在需要更高级别的安全性和身份验证. 但是,仍然可以不使用允许安全性较低的应用程序"选项使用它,但是您不能使用标准的Google用户名和密码.

Google changed some time ago (one or two years ago) possibility to use its SMTP servers. Google now requires higher level of security and authentication. However there still is a possibility to use it without 'Allow less secure apps' option, but you cannot use your standard google username and password.

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

Here is how to do it (in short):

  1. 在我的帐户/登录和登录"的Gmail或Google Apps帐户中启用两步验证.安全",
  2. 然后(在我的帐户/登录和安全性/应用程序密码"中)可以生成一个特殊密码,供其他应用程序访问(如果未启用两步验证,则无法到达该位置)
  3. 此创建的应用密码(以及您的Google电子邮件帐户作为用户名),然后可以用作SMTP登录名.
  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.

仅此而已.

这篇关于有没有一种方法可以使用ASP.NET通过Google Apps帐户发送电子邮件,而无需选择“允许不太安全的应用程序"选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆