Trying to connect to imap using MailKit library. While this code works for Gmail and hot mail. It gives Login Failed error for Office 365.
using (var client = new ImapClient(new ProtocolLogger("imap.log")))
{
client.Timeout = 120000;
client.Connect("outlook.office365.com",
93,SecureSocketOptions.SslOnConnect);
client.Authenticate("xxxxx@xxxxinet.com", "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 has Deprecated basic authentication starting from 2023. You can read more about it on their article Deprecation of Basic authentication in Exchange Online
You need to use Oauth2 authentication Authenticate an IMAP, POP or SMTP connection using OAuth
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.