使用Gmail发送电子邮件。错误:服务器响应为:5.5.1需要身份验证 [英] Send email using gmail. Error: The server response was: 5.5.1 Authentication Required

查看:755
本文介绍了使用Gmail发送电子邮件。错误:服务器响应为:5.5.1需要身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对不起,我看到了关于这件事情有很多类似的帖子,但从来没有发现任何解决我的问题,所以我决定将它张贴。

Sorry, I saw a lot of similar post regarding this matter but never found any solution to my problem, so I decided to post it.

我正在使用ASP.NET C#编程发送电子邮件使用Gmail以下code。

I am using ASP.NET c# to send email programmatically using gmail with the following code.

 string EmailAddress = senderemail;
    MailMessage mailMessage = new MailMessage(EmailAddress, EmailAddress);
    mailMessage.Subject = "This is a test email";
    mailMessage.Body = "This is a test email. Please reply if you receive it.";

    SmtpClient smtpClient = new SmtpClient();
    smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
    smtpClient.EnableSsl = true;
    smtpClient.Host = "smtp.gmail.com";
    smtpClient.Port = 587;

    smtpClient.Credentials = new System.Net.NetworkCredential()
    {
        UserName = EmailAddress,
        Password = senderpassword
    };
    smtpClient.UseDefaultCredentials = false;
    smtpClient.Send(mailMessage);

我收到此错误和其他人一样。

I received this error like everybody else

错误:

SMTP服务器要求安全连接或客户端未
  验证。服务器响应为:5.5.1需要验证。
  了解更多。

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at.

已经没有低于2行动从GMAIL。

Already did below 2 action from GMAIL.

-less安全的应用程序:打开

-less secure app : turn on

-2两步验证:关

我不在乎是否是此Gmail帐户安全还是什么。我不需要为这个帐户任何安全性。我应该做些什么呢?

I don't care whether is this gmail account safe or what. I don't need any security for this account. What else should i do?

推荐答案

注册Gmail和去的 https://www.google.com/settings/security/lesssecureapps 在这里你可以看到设置。不够安全的应用访问

sign up Gmail and go to https://www.google.com/settings/security/lesssecureapps where you can see settings. Access for less secure apps

关闭(默认)==>打开

添加此code后,

  MailMessage mail = new MailMessage("fromm@gmail.com", "toaddress@gmail.com");
                mail.Subject = "TestEmailImportant";
                mail.Body = "This mail is to test if this program is working";

                SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587);

                smtpClient.Credentials = new System.Net.NetworkCredential()
                {
                    UserName = "XXXXXX@gmail.com",
                    Password = "YYYYYYYY"
                };

                smtpClient.EnableSsl = true;
                System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate(object s,
                        System.Security.Cryptography.X509Certificates.X509Certificate certificate,
                        System.Security.Cryptography.X509Certificates.X509Chain chain,
                        System.Net.Security.SslPolicyErrors sslPolicyErrors)
                {
                    return true;
                };

                smtpClient.Send(mail);

这篇关于使用Gmail发送电子邮件。错误:服务器响应为:5.5.1需要身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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