Reading mails using IMAP and OAuth2 - A01 NO AUTHENTICATE

Mark Vorster 1 Reputation point

Hi there,

I created a new O365 account and I am using the default email address to test this. I followed the common pattern to activate OAuth2 for accessing mails via IMAP. I am able to retrieve a token (using scope, but when I try to read the mails from the mailbox I get the following error: A01 NO AUTHENTICATE

I followed the steps on this link:

I created an application, generated a secret key, added API permissions (screenshot attached)

I have also added offline access and email to this list, still not able to authenticate.

And I am able to make the call. I tested the OAUTH call and login with details from a mailbox that I know work, so I know its nothing wrong with the API call itself, its got something to do with the mailbox.

I also activated IMAP on the mailbox itself.

Does anyone know how I can get this to work?

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,112 questions
Microsoft 365 Publishing
Microsoft 365 Publishing
Microsoft 365: Formerly Office 365, is a line of subscription services offered by Microsoft which adds to and includes the Microsoft Office product line. Publishing: The process of preparing, producing, and releasing content for distribution or sale.
603 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Niraj Kumar 5 Reputation points

    I think that you have made a mistake on creating the Service Principal account

    The OBJECT_ID is the Object ID from the Overview page of the Enterprise Application node (Azure Portal) for the application registration. It is not the Object ID from the Overview of the App Registrations node. Using the incorrect Object ID will cause an authentication failure.

    Ref article:

    1 person found this answer helpful.
    0 comments No comments

  2. Glen Scales 4,431 Reputation points

    Your missing the Application permissions for IMAP which are located under Office365 Exchange Online (all your current permissions are for the Graph which won't work for IMAP) . You need to select this from the API's my Organization uses under the Azure portal eg


    The add the app permission for IMAP and Consent


    The other thing that must be done and can't be skipped is

    Register service principals in Exchange

    Explictly Grant Access to the Mailboxes the applicaiton will use eg
    Add-MailboxPermission -Identity "john.smith@Company portal .com" -User <SERVICE_PRINCIPAL_ID> -AccessRights FullAccess

    (You need to wait up to 15 minutes for these change to apply)