oAuth2 Outlook Office365 & Pop3 - Client Credential Grant Flow

Gavin Holmes 11 Reputation points
2022-09-28T15:02:06.237+00:00

Ive gone through all the documentation i can find (this one is fantastic https://www.youtube.com/watch?v=bMYA-146dmM&t=609s)

But for the life of me I cannot get POP3 to work.

IMAP etc works fine. But its just plain not authenticating, I'm sure its something simple, but nothing is glaring out .

Im using MailKit.Net.Pop3 to do the connection,

var oauth2 = new SaslMechanismOAuth2(Email, Token);
using (var client2 = new MailKit.Net.Pop3.Pop3Client(new ProtocolLogger("pop3.log")))
{

//client2.AuthenticationMechanisms.Add("XOAUTH2");  
await client2.ConnectAsync("outlook.office365.com", 995, SecureSocketOptions.Auto);  

await client2.AuthenticateAsync(oauth2);     <-----  Error MailKit.Net.Pop3.Pop3ProtocolException: 'POP3 server did not respond with a +OK response to the AUTH command.'  
var UIDs = client2.GetMessageUids();  
await client2.DisconnectAsync(true);  

}

The JWT has this scope:

"roles": [
"Mail.ReadWrite",
"POP.AccessAsApp",
"Mail.Read",
"Mail.Send",
"IMAP.AccessAsApp"
]

As said i can use the same Authentication on ImapCLient and is totally fine.

THe User has Pop3 enabled for the Email account, PLEASE HELP !!!

I really dont wat to rewrite loads of apps away from POP this close to switch over from Microsoft !!

This is the log results:

S: +OK The Microsoft Exchange POP3 service is ready. [TABPADQAUAAxADIAMwBDAEEAMAAzADAAOAAuAEcAQgBSAFAAMQAyADMALgBQAFIATwBEAC4ATwBVAFQATABPAE8ASwAuAEMATwBNAA==]
C: CAPA
S: +OK
S: TOP
S: UIDL
S: SASL PLAIN XOAUTH2
S: USER
S: .
C: AUTH XOAUTH2
S: +

Microsoft Office Online Server
Microsoft Office Online Server
Microsoft on-premises server product that runs Office Online. Previously known as Office Web Apps Server.
647 questions
Exchange Server Development
Exchange Server Development
Exchange Server: A family of Microsoft client/server messaging and collaboration software.Development: The process of researching, productizing, and refining new or existing technologies.
547 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.