【发布时间】:2015-11-03 10:06:28
【问题描述】:
根据新的谷歌政治https://googleonlinesecurity.blogspot.de/2014/04/new-security-measures-will-affect-older.html我无法发送电子邮件。对于不使用 OAuth 2.0 的应用程序,Google 会考虑“不太安全的应用程序”。
我想用MailKit来解决这个问题
var message = new MimeMessage();
message.From.Add(new MailboxAddress("Joey Tribbiani", "noreply@localhost.com"));
message.To.Add(new MailboxAddress("Mrs. Chanandler Bong", "mymail@gmail.com"));
message.Subject = "How you doin'?";
message.Body = new TextPart("plain"){ Text = @"Hey" };
using (var client = new SmtpClient())
{
client.Connect("smtp.gmail.com", 587);
////Note: only needed if the SMTP server requires authentication
client.Authenticate("mymail@gmail.com", "mypassword");
client.Send(message);
client.Disconnect(true);
}
但我有An exception of type 'MailKit.Security.AuthenticationException' occurred in MailKit.dll but was not handled in user code.Additional information: Authentication failed.
我不想更改我的安全设置。因为我希望一切都安全。这就是我开始使用 MailKit 而不是 System.Net.Mail 的原因
我该如何解决?
【问题讨论】:
-
这不是关于 mailkit 或 C#,而是关于 Google。要么密码错误,要么需要更改账号as shown here的安全设置
-
我相信这是因为您需要设置与 Oauth 2.0 的连接 github.com/jstedfast/MailKit/blob/…
-
实际上,即使密码看起来正确,GMail 也会返回身份验证错误的原因有多种 - 一次密码,两次身份验证as described here