[英]Error on sending email using gmail. The SMTP server requires a secure connection or the client was not authenticated
Here is my code. 这是我的代码。
var smtp = new SmtpClient("smtp.gmail.com", 587)
{
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential("sender@gmail.com","123")
};
try
{
smtp.Send("sender@gmail.com", "receiver@gmail.com", "test", "testbody");
}
catch (SmtpException e)
{
ltrInfo.Text=e.Message;
}
When I debug the code, I get the error "The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required" Please can you tell me what's the wrong with the code above? 调试代码时,出现错误“ SMTP服务器需要安全连接或客户端未通过身份验证。服务器响应为:5.5.1需要身份验证”请您告诉我上面的代码有什么问题吗?
Everything looks ok. 一切看起来还好。
Here are 2 possible solutions 这是2种可能的解决方案
Get to your Gmail account's security settings and set permissions for "Less secure apps"
to Enabled. 转到您的Gmail帐户的安全设置,然后将
"Less secure apps"
权限设置为"Less secure apps"
启用”。
Check if there is not a "Suspicious login attempt"
on the top of the page, if is there click to authorizing the access 检查页面顶部是否没有
"Suspicious login attempt"
,如果存在,请单击以授权访问
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.