尝试使用 MailKit 库连接到 imap。虽然此代码适用于 Gmail 和热邮件。 它给出 Office 365 登录失败错误。
using (var client = new ImapClient(new ProtocolLogger("imap.log")))
{
client.Timeout = 120000;
client.Connect("outlook.office365.com",
93,SecureSocketOptions.SslOnConnect);
client.Authenticate("[email protected]", "XXXXXPassword");
client.Inbox.Open(FolderAccess.ReadOnly);
var uids = client.Inbox.Search(SearchQuery.All);
foreach (var uid in uids)
{
var message = client.Inbox.GetMessage(uid);
// write the message to a file
message.WriteTo(string.Format("{0}.eml", uid));
}
client.Disconnect(true);
}
Microsoft 从 2023 年开始已弃用基本身份验证。您可以在他们的文章在 Exchange Online 中弃用基本身份验证
了解更多相关信息您需要使用 Oauth2 身份验证 使用 OAuth 对 IMAP、POP 或 SMTP 连接进行身份验证
但我可以使用我的 apppass 发送电子邮件,而 System.Net.Mail 只能接收电子邮件,但无法正常工作...为什么?