简体   繁体   English

使用 asp.net 发送电子邮件显示此错误:SMTP 服务器需要安全连接或客户端未通过身份验证

[英]Send email using asp.net shows this error:The SMTP server requires a secure connection or the client was not authenticated

I try to send email using this code:我尝试使用此代码发送电子邮件:

  public void Semail(string subject, string messageBody, string toAddress)
        {
            MailMessage mail = new MailMessage();
            mail.To.Add(toAddress);
            //mail.To.Add("amit_jain_online@yahoo.com");
            mail.From = new MailAddress("noreplykaramaoozi@eesharif.edu");
            mail.Subject = subject;
            string Body = messageBody;
            mail.Body = Body;
            mail.IsBodyHtml = true;
            SmtpClient smtp = new SmtpClient();
            smtp.Host = "sina.sharif.ir"; //Or Your SMTP Server Address
            smtp.Port = 587;
            smtp.Credentials = new System.Net.NetworkCredential
                ("noreplykaramaoozi@eesharif.edu", "*******");
            //Or your Smtp Email ID and Password
            smtp.EnableSsl = false;
            smtp.Send(mail);
        }

But after executing i got this error:但是执行后我得到了这个错误:

 The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Authentication required 

Stack Trace :堆栈跟踪 :

[SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Authentication required]
   System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response) +2162008
   System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, String from) +287
   System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception) +137
   System.Net.Mail.SmtpClient.Send(MailMessage message) +2188821
   Novitiate.fa.Register.btnLogin_Click(Object sender, EventArgs e) +2948
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +154
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3707

Best regards此致

Your gmail security preventing the message to access the gmail account.您的 Gmail 安全阻止了邮件访问 Gmail 帐户。 So,if you want to send the message you have to "turn off" the access for less secure app.因此,如果您想发送消息,您必须“关闭”安全性较低的应用程序的访问权限。 When you do this you can easily send the message but, by risking your gmail security.当您这样做时,您可以轻松地发送邮件,但会冒着 Gmail 安全的风险。 So, it is upto you this definitely work.所以,这完全取决于你。

link for changing security is given below下面给出了更改安全性的链接

https://www.google.com/settings/security/lesssecureapps?pli=1 https://www.google.com/settings/security/lesssecureapps?pli=1

Try this one if this helps:如果这有帮助,请尝试以下方法:

MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
mail.From = new MailAddress(Username);
mail.To.Add(TxtEmail.Text);
mail.Subject = Subject;
mail.Body = Body;
SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential(Username, Password);
SmtpServer.EnableSsl = true;
SmtpServer.Timeout = 20000;
SmtpServer.Send(mail);

登录到您的电子邮件帐户后,请考虑 @Krunal Patil 在那里的回答,并对发送的验证邮件进行操作以授予对您的 C# 应用程序的访问权限。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SMTP服务器需要安全连接,或者客户端未在C#ASP.NET中进行身份验证 - The SMTP server requires a secure connection or the client was not authenticated in C# ASP.NET asp.net中的密码恢复SMTP服务器需要安全连接或客户端未通过身份验证 - Password Recovery in asp.net The SMTP server requires a secure connection or the client was not authenticated 使用gmail发送电子邮件时出错。 SMTP服务器需要安全连接或客户端未通过身份验证 - Error on sending email using gmail. The SMTP server requires a secure connection or the client was not authenticated SMTP服务器需要安全连接或客户端未经过身份验证 - The SMTP server requires a secure connection or the client was not authenticated SMTP 服务器需要安全连接或客户端未通过身份验证 - 错误 - The SMTP server requires a secure connection or the client was not authenticated - Error SMTP 服务器需要安全连接或客户端未通过身份验证。 服务器响应为:5.7.57 SMTP; Office 365 错误 - The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.57 SMTP; Office 365 error 出现错误:SMTP 服务器需要安全连接或客户端未通过身份验证。 服务器响应为:5.7.57 SMTP - Getting error : The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.57 SMTP SMTP服务器需要安全连接,或者客户端未通过身份验证-连接超时 - The SMTP server requires a secure connection or the client was not authenticated— connection timed out 在服务器上获取异常SMTP服务器需要安全连接或客户端未通过身份验证 - On server Getting exception The SMTP server requires a secure connection or the client was not authenticated 如何修复 GMail SMTP 错误:“SMTP 服务器需要安全连接或客户端未通过身份验证。” - How to fix GMail SMTP error: "The SMTP server requires a secure connection or the client was not authenticated."
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM