如何处理 MailKit.Security.AuthenticationException: 'LOGIN failed.'



我正试图使用MailKit库从邮箱中读取电子邮件。很遗憾,该程序引发了此MailKit.Security.AuthenticationException:"LOGIN失败。"凭据匹配(我尝试通过浏览器登录(。我正在尝试使用MailKit库读取邮箱中的电子邮件。不幸的是,程序抛出了这个

MailKit.Security.AuthenticationException:"LOGIN失败。">

如果有任何帮助,我将不胜感激,我不知道该怎么办。我在谷歌上搜索,尝试了这个client.Connect("imap.outlook.com", 993, SecureSocketOptions.None);但什么也没发生当我将SecureSocketOptions更改为Auto时,引发了相同的异常

using (var client = new ImapClient())
{
using (var cancel = new CancellationTokenSource())
{
client.Connect("imap.outlook.com", 993, true);

//client.AuthenticationMechanisms.Remove("XOAUTH");
client.Authenticate("mail@test.cz", "password", cancel.Token);

var inbox = client.Inbox;
inbox.Open(FolderAccess.ReadOnly, cancel.Token);
Console.WriteLine("Total messages: {0}", inbox.Count);
Console.WriteLine("Recent messages: {0}", inbox.Recent);

for (int i = 0; i < inbox.Count; i++)
{
var message = inbox.GetMessage(i, cancel.Token);
Console.WriteLine("Subject: {0}", message.Subject);
}

var query = SearchQuery.DeliveredAfter(DateTime.Parse("2013-01-12"))
.And(SearchQuery.SubjectContains("MailKit"))
.And(SearchQuery.Seen);
foreach (var uid in inbox.Search(query, cancel.Token))
{
var message = inbox.GetMessage(uid, cancel.Token);
Console.WriteLine("[match] {0}: {1}", uid, message.Subject);
}
client.Disconnect(true, cancel.Token);
}
}

AuthenticationException与SSL无关,因此与client.Connect(...)无关。这是client.Authenticate (username, password)的问题

微软的公共电子邮件服务器不再允许使用用户名和密码。它们现在需要通过OAuth2进行身份验证。

有关如何使用OAuth2进行身份验证的信息,请参阅MailKit文档:https://github.com/jstedfast/MailKit/blob/master/ExchangeOAuth2.md

相关内容

  • 没有找到相关文章

最新更新