问题描述
我终其一生都无法弄清楚为什么这不起作用
I cannot figure out for the life of my why this isn't working
SmtpClient smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
UseDefaultCredentials = false,
DeliveryMethod = SmtpDeliveryMethod.Network,
Credentials = new NetworkCredential("myemail@gmail.com", "myGmailPasswordHere"),
EnableSsl = true,
Timeout = 10000
};
smtp.Send(mail);
我明白了:
SMTP 服务器需要安全连接或客户端未通过身份验证.服务器响应为:5.5.1 Authentication Required.
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.
我刚刚将 EnableSsl 指定为 true,因此这不应该是安全连接方面的问题.
I just specified EnableSsl to true so that shouldn't be the issue in terms of secure connection.
我从 localhost 运行它.是的,我输入身份验证的用户名和密码(我的 gmail 帐户凭据)是 100% 正确的.
I'm running this from localhost. And yes, my username and password I'm entering to auth (my gmail account credentials) is 100% right.
推荐答案
我知道这是个老话题了,但是……谷歌已经改变了他们的安全设置.
I know this is an old topic, BUT... Google has changed something on their security settings.
我一直在为所有答案苦苦挣扎,直到我检查了我的电子邮件,并收到一封来自 Google 的邮件,其中说我们最近阻止了对您的 Google 帐户的登录尝试".
Was struggling with all the answers until I checked my email with a mail from Google stating that "we've recently blocked a sign-in attempt on your Google account".
这使我进入了这个页面:Google 帐户安全
That led me to this page: Google Account Security
在访问安全性较低的应用程序"部分下,您可以允许从其他设备/应用程序访问您的帐户...例如您的 C# 应用程序.
Under the "Access for less secure apps" section, you can enable access to your account from other devices/applications... like your C# application.
请注意,不再有特定于应用程序"的部分.
Note, there is no longer an "application specific" section.
希望这对某人有所帮助...我刚刚失去了 30 分钟的生命...
Hope this helps someone... I just lost 30 minutes of my life...
这篇关于无法通过 MailMessage 对 Gmail smtp 进行身份验证smtpClient的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!