无法发送电子邮件 - 错误:SMTP服务器需要安全连接或客户端未经过身份验证。服务器响应为:5.5.1需要身份验证。了解更多信息 [英] Could not send the e-mail - error: 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
本文介绍了无法发送电子邮件 - 错误:SMTP服务器需要安全连接或客户端未经过身份验证。服务器响应为:5.5.1需要身份验证。了解更多信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
protected void Button1_Click(object sender, EventArgs e)
{
try
{
SmtpClient smtp= new SmtpClient("smtp.gmail.com", 587);
smtp.EnableSsl = true;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new System.Net.NetworkCredential("computersaddict.himanshu@gmail.com", "password");
smtp.Timeout = 30000;
MailMessage message = new MailMessage();
message.To.Add("himanshu92chawla@gmail.com");
message.From = new MailAddress("computersaddict.himanshu@gmail.com");
message.Subject = "Test Mail";
message.Body = "This is for testing SMTP mail from GMAIL";
smtp.Send(message);
Response.Write("E-mail sent!");
}
catch (Exception ex)
{
Response.Write("Could not send the e-mail - error: " + ex.Message);
}
}
推荐答案
确保用户名和密码在行中正确无误:
Make sure the username and password is correct in the line:
smtp.Credentials = new System.Net.NetworkCredential("computersaddict.himanshu@gmail.com", "password");
尝试评论该行:
try commenting the line :
smtp.UseDefaultCredentials = false;
还尝试在构造函数外部设置属性:
Also try setting the properties outside the constructor:
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
按照以下步骤检查解决方案1 。
1) https://accounts.google.com/DisplayUnlockCaptcha [ ^ ] //点击允许访问您的Google帐户
2)你必须为你的谷歌帐户启用从其他时区/ IP登录。
这样做是按照链接 https://g.co/allowaccess [ ^ ]并允许通过单击继续按钮进行访问。
3)转到以下链接的安全设置 https://www.google.com/ settings / security / lesssecureapps [ ^ ]和启用不太安全的应用。这样您就可以从所有应用程序登录。
Hi,
Check the solution 1 after follow this below steps.
1) https://accounts.google.com/DisplayUnlockCaptcha[^] //Click allow access to your Google account
2) You have to enable login from other timezone / ip for your google account.
to do this follow the link https://g.co/allowaccess[^] and allow access by clicking the continue button.
3) go to security settings at the followig link https://www.google.com/settings/security/lesssecureapps[^] and enable less secure apps . So that you will be able to login from all apps.
这篇关于无法发送电子邮件 - 错误:SMTP服务器需要安全连接或客户端未经过身份验证。服务器响应为:5.5.1需要身份验证。了解更多信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文