只有当帐户具有“访问安全性较低的应用程序”权限时,才能通过Gmail帐户发送电子邮件。启用 [英] Can send emails through Gmail account only if account has "Access for less secure apps" enabled

查看:3214
本文介绍了只有当帐户具有“访问安全性较低的应用程序”权限时,才能通过Gmail帐户发送电子邮件。启用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我的Gmail帐户访问安全性较低的应用 禁用,那么我的应用无法发送邮件通过这个帐户。相反,我得到 SMTP服务器需要一个安全连接或者客户端没有通过认证,服务器响应是:5.5.1 Authentication Required 异常。



此处 Google解释说,通过禁用 使用安全性较低的应用程序可以访问,只有使用现代安全标准的应用程序才可以登录。

我的代码需要实现哪些现代安全标准,并且可以告诉我如何使用示例实现它们(不确定它是否重要,但是我的应用程序和 Gmail帐户没有使用两步验证)?



以下是代码I 'm当前使用:

  public class EmailService:IIdentityMessageService 
{
public Task SendAsync(IdentityMessage message)
{
var credentialUserName =myAccount@gmail.com;
var sentFrom =myAccount@gmail.com;
var pwd =myPwd;

System.Net.Mail.SmtpClient客户端=
新System.Net.Mail.SmtpClient(smtp.gmail.com);

client.Port = 587;
client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;

System.Net.NetworkCredential凭证=
新System.Net.NetworkCredential(credentialUserName,pwd);

client.EnableSsl = true;
client.Credentials =凭证;

var mail =
新System.Net.Mail.MailMessage(sentFrom,message.Destination);

mail.Subject = message.Subject;
mail.Body = message.Body;

返回client.SendMailAsync(mail);
}
}


解决方案

asp.net-identity-2 标记应用于此问题,并考虑到Google需要使用 OAuth 2.0 以避免必须使用 Access for安全性较低的应用程序选项,似乎有一个选项是使用 OWIN中间件能够通过在 www.asp中搜索术语 Oauth 2.0 找到.net



此网站托管文章。 MVC 5应用程序与Facebook,Twitter,LinkedIn和Google OAuth2登录可能有一些利益。该文章似乎展示了许多截图,这些截图通过获取资源,创建应用程序以及使用 Google 服务器进行身份验证的过程。

If my Gmail account has Access for less secure apps disabled, then my application can't send emails through this account. Instead I get "The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required" exception.

Here Google explains that by disabling Access for less secure apps, only apps that use modern security standards can sign in.

What are those modern security standards my code needs to implement and can you show me how to implement them with an example ( not sure if it matters, but my app and Gmail account aren't using 2-step verification )?

Here's the code I'm currently using:

public class EmailService : IIdentityMessageService
{
    public Task SendAsync(IdentityMessage message)
    {
        var credentialUserName = "myAccount@gmail.com";
        var sentFrom = "myAccount@gmail.com";
        var pwd = "myPwd";

        System.Net.Mail.SmtpClient client = 
            new System.Net.Mail.SmtpClient("smtp.gmail.com");

        client.Port = 587;
        client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
        client.UseDefaultCredentials = false;

        System.Net.NetworkCredential credentials = 
            new System.Net.NetworkCredential(credentialUserName, pwd);

        client.EnableSsl = true;
        client.Credentials = credentials;

        var mail = 
            new System.Net.Mail.MailMessage(sentFrom, message.Destination);

        mail.Subject = message.Subject;
        mail.Body = message.Body;

        return client.SendMailAsync(mail);
    }
}

解决方案

Considering that the asp.net-identity-2 tag is applied to this question, and considering that Google requires use of OAuth 2.0 to avoid having to use the Access for less secure applications option, it appears that one option is to use the OWIN middleware able to be found by searching for the term Oauth 2.0 at www.asp.net.

This site hosts an article titled Code! MVC 5 App with Facebook, Twitter, LinkedIn and Google OAuth2 Sign-on that might be of some interest. The article appears to show many screenshots that walk a developer through the process of getting the resource, creating an app, and authenticating with a Google server.

这篇关于只有当帐户具有“访问安全性较低的应用程序”权限时,才能通过Gmail帐户发送电子邮件。启用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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