0 votes

Hello,

We are trying to use Pop3 using Office365 accounts and OAuth, but not able to do this.
We have a valid token, but when we connect to outlook.office365.com and check available methods, there are only User and Basic:

pop3.ConnectSSL("outlook.office365.com");
var sup = pop3.SupportedAuthenticationMethods();

If we still use LoginOAUTH2 method, we get the error:

Limilabs.Client.POP3.Pop3ResponseException:
'Protocol error. Connection is closed. 10'

Any help?

by (201 points)

1 Answer

0 votes

[Edited]

Office365 stared supporting OAuth 2.0 for POP3. Mail.dll supports it as well:

using (Pop3 pop3 = new Pop3())
{
    pop3.ConnectSSL("outlook.office365.com");
    pop3.LoginOAUTH2("<email>", accessToken);

    // ...

    pop3.Close();
}

Answer below applies to the older version of Office365.

Well, this is what the server returns:

 C: CAPA
 S: +OK
 S: TOP
 S: UIDL
 S: SASL PLAIN
 S: USER
 S: .

XOAUTH2 is missing.

To be honest I don't know if they support OAUTH2 for POP3.

Is there any info on the web that they support OAUTH2?
What scope are you using to obtain a token?

by (272k points)
edited by
Based on their statement - yes.
https://developer.microsoft.com/en-us/office/blogs/end-of-support-for-basic-authentication-access-to-exchange-online-apis-for-office-365-customers/

It's also not possible to login into Outlook.com (pop-mail.outlook.com) using POP3 OAuth, while it's possible to do this using IMAP (following your guide for IMAP OAuth Outlook).

Not sure if the scope matters, but for Outlook.com we used: "wl.imap", "wl.emails", "wl.offline_access"
And for outlook.office365.com we used:
Mail.ReadWrite Mail.Send offline_access
(based on the new mail api reference)
To be honest it looks like it is simply not implemented by them, for both pop-mail.outlook.com and outlook.office365.com.

People also report it doesn't work for Azure hosted Exchange and IMAP.

I was just curious about the scope.
I found their blog post from Tuesday https://techcommunity.microsoft.com/t5/exchange-team-blog/basic-auth-and-exchange-online-february-2020-update/ba-p/1191282

Looks like it should be implemented now:
"POP, IMAP and SMTP
The next piece of news we want to share is an update on the status of adding Modern Auth support to POP and IMAP for O365 commercial customers (we’ve had Modern Auth for IMAP in consumer Outlook.com for years).
We’ve completed our development work and are rolling out Modern Auth support for POP and IMAP in Exchange Online now."
Hi again,
Based on this blogpost: https://techcommunity.microsoft.com/t5/exchange-team-blog/announcing-oauth-support-for-pop-in-exchange-online/ba-p/1406600

POP3 is now supported by Exchange Online and it's listed in the supported authentication methods of Pop3 client. However, when we try to perform LoginOAUTH2 method we recieve an error:
Limilabs.Client.POP3.Pop3ResponseException: 'Protocol error. Connection is closed. 10'

At the same moment IMAP client works just fine.

I also took a random product from the internet similar to Limilabs and was able to connet using POP3 OAuth2 without any issues.

The code I'm using:

            using (Pop3 pop3 = new Pop3())
            {
                pop3.ConnectSSL("outlook.office365.com", 995);
                var sup3 = pop3.SupportedAuthenticationMethods();
                pop3.LoginOAUTH2("<my_email>", accessToken);
            }

Any help is appreciated.
Can you please send the logs directly to us so we can investigate?

You can find the address in the page footer.
...