无法使用Gmail的应用程序密码从C#Win表单应用发送电子邮件
我们曾经发送带有不太安全的应用程序选项的电子邮件,这是不再可能的。我已经设置了两种身份验证,我创建了一个应用程序密码,但是当我尝试发送带有应用程序密码的电子邮件而不是帐户密码时,我会收到错误:
System.Net.Mail.SmtpException: Failure sending mail.
---> System.IO.IOException: Unable to read data from the transport connection: The connection was closed.
发送的代码为:
Smtp = new SmtpClient();
Smtp.UseDefaultCredentials = false;
var NetworkCredentials = new NetworkCredential() { UserName = "[email protected]", Password = "..." };
Smtp.Port = 587;
Smtp.EnableSsl = true;
Smtp.Host = "smtp.gmail.com";
Smtp.Credentials = NetworkCredentials;
MailMessage msg = new MailMessage();
msg.From = new MailAddress("[email protected]");
msg.To.Add("[email protected]");
msg.Subject = "test";
Smtp.Send(msg);
We used to send emails with the Less secure apps option, which is no longer possible. I have setup the 2 way authentication, I have created an app password, but when I try to send an email with the app password instead of the account password I get the error :
System.Net.Mail.SmtpException: Failure sending mail.
---> System.IO.IOException: Unable to read data from the transport connection: The connection was closed.
The code for sending is :
Smtp = new SmtpClient();
Smtp.UseDefaultCredentials = false;
var NetworkCredentials = new NetworkCredential() { UserName = "[email protected]", Password = "..." };
Smtp.Port = 587;
Smtp.EnableSsl = true;
Smtp.Host = "smtp.gmail.com";
Smtp.Credentials = NetworkCredentials;
MailMessage msg = new MailMessage();
msg.From = new MailAddress("[email protected]");
msg.To.Add("[email protected]");
msg.Subject = "test";
Smtp.Send(msg);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论