[英]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.