0 votes

I have done setting as per below links:

https://www.limilabs.com/blog/office365-enable-imap-pop3-smtp

https://www.limilabs.com/blog/office365-app-passwords

Now please find below code i am trying to run it gives me Authentication Failure error.

using (Imap imap = new Imap())
{
    imap.ConnectSSL("outlook.office365.com");

    imap.UseBestLogin("UserNameEnteredHere", "AppPassword");

    imap.SelectInbox();

    List<long> uids = imap.Search(Flag.Unseen);

    foreach (long uid in uids)
    {
        IMail email = new MailBuilder()
            .CreateFromEml(imap.GetMessageByUID(uid));
        string subject = email.Subject;
    }
    imap.Close();
}
by
edited by

1 Answer

0 votes

Basic Authentication +app passwords or +main account password still work with Office 365 (I just checked to be 100% sure).

That means that:
- Your AD prevents basic authentication
- or you have IMAP disabled on Exchange or mailbox level.

Things you must check:
- Exchange: Org settings that allow IMAP usage (+modern authentication for OAuth)
- Exchange: specific mailbox settings that allow IMAP
- AD: enabled security defaults set to No
- AD: no conditional access policies or policies that allow for IMAP

All those steps are explained in detail here:
https://www.limilabs.com/blog/office365-enable-imap-pop3-smtp

Have in mind it takes 20-30 minutes for the changes to take effect (it really can take this long!).

Note: Basic Authentication is scheduled to be retired on October 1st, 2022 - consider switching to one of the OAuth flows:

Daemons/Services: Password grant (MFA/2FA must be turned off for this account):
https://www.limilabs.com/blog/oauth2-password-grant-office365-exchange-imap-pop3-smtp

Daemons/Services: Client credential flow:
https://www.limilabs.com/blog/oauth2-client-credential-flow-office365-exchange-imap-pop3-smtp

Web apps (requires user interaction):
https://www.limilabs.com/blog/oauth2-web-flow-office365-exchange-imap-pop3-smtp

Standalone devices (requires very little interaction):
https://www.limilabs.com/blog/oauth2-device-flow-office365-exchange-imap-pop3-smtp

Desktop apps (requires user interaction):
https://www.limilabs.com/blog/oauth2-office365-exchange-imap-pop3-smtp

by (301k points)
...