使用gmail发送电子邮件时出错。 SMTP服务器需要安全连接或客户端未通过身份验证 [英] Error on sending email using gmail. The SMTP server requires a secure connection or the client was not authenticated
问题描述
这是我的代码。
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;
}
当我调试代码时,我收到错误SMTP服务器需要服务器响应是:5.5.1验证需要
请问你可以告诉我上面的代码有什么问题吗?
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?
推荐答案
一切看起来都可以。
以下是两种可能的解决方案:
Here are 2 possible solutions
访问您的Gmail帐户的安全设置,并为较不安全的应用
设置为已启用权限。
Get to your Gmail account's security settings and set permissions for "Less secure apps"
to Enabled.
检查页面顶部是否没有可疑登录尝试
,如果有点击授权访问
Check if there is not a "Suspicious login attempt"
on the top of the page, if is there click to authorizing the access
查看这个
告诉我是否有效。
take a look on this Tell me if works.
这篇关于使用gmail发送电子邮件时出错。 SMTP服务器需要安全连接或客户端未通过身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!