0
votes

I have read every MailKit problem, but mine still will NOT work. I have removed my actual logins passwords, but they are correct for the account.

using (var client = new ImapClient(new ProtocolLogger(@"c:\temp\imaplog.txt")))
{
    try
    {
        client.Connect("outlook.office365.com", 993, true);
        client.AuthenticationMechanisms.Remove("XOAUTH2");
        client.AuthenticationMechanisms.Clear();
        client.SslProtocols = SslProtocols.Tls;
        client.Authenticate(<username>,<password>);
        //var inbox = client.mai;
        //inbox.Open(FolderAccess.ReadWrite);
        //var uids = await inbox.SearchAsync(MailKit.Search.SearchQuery.NotSeen);
    }
    catch (Exception exc)
    {
    }
}

IMAP logfile

Connected to imaps://outlook.office365.com:993/
S: * OK The Microsoft Exchange IMAP4 service is ready. [UwBOADYAUABSADAAMQBDAEEAMAAwADAAMwAuAHAAcgBvAGQALgBlAHgAYwBoAGEAbgBnAGUAbABhAGIAcwAuAGMAbwBtAA==]
C: A00000000 CAPABILITY
S: * CAPABILITY IMAP4 IMAP4rev1 AUTH=PLAIN AUTH=XOAUTH2 SASL-IR UIDPLUS MOVE ID UNSELECT CHILDREN IDLE NAMESPACE LITERAL+
S: A00000000 OK CAPABILITY completed.
C: A00000001 LOGIN username password
S: A00000001 NO LOGIN failed.
1
Is MailKit sending the correct username and password strings to the server? Does your username include the @domain portion of the account email address? What if you try not including it or including it (i.e. do the opposite of what you are doing)? What happens if you remove client.AuthenticationMechanisms.Clear(); to allow MailKit to use PLAIN authentication? Make sure to try with and without the @domain when testing with PLAIN as well. - jstedfast
I have tried everything you said, to no avail. If I include the domain, it would look like domain/username, password correct? - Steve Wisnieski
No, it would look like [email protected] or [email protected]. - jstedfast

1 Answers

0
votes

You need to go into your Office365 settings and make sure to allow IMAP logins via "less secure apps".

FYI: https://developer.microsoft.com/en-us/office/blogs/end-of-support-for-basic-authentication-access-to-exchange-online-apis-for-office-365-customers/

In other words, you'll need to start using XOAUTH2 by October 2020.