Trying to use Azure + Graph API to read emails from my outlook email.

Sacha Baniassad 0 Reputation points
2024-06-26T02:38:31.67+00:00

Hello,

I have been trying for quite some time now to use the Graph API in combination with Azure to read the messages inside of my outlook email's inbox. I am doing this in Python. I have been very thorough with the https://developer.microsoft.com/en-us/graph/graph-explorer tool, and I have noticed that it works flawlessly when I make requests using the "/me/" path on my endpoint:
User's image

However, with that being said, this setup is unsuitable for my production usage, because I have also noticed that the "/me/" path requires for you to have authentication a session and logged in.

Instead, I am trying to use the "/users/{user-id}/" path to fetch and read emails from from my outlook email's inbox, which I read does not require a manual user sign-in. For example, here is the endpoint that I would like to have work (I am trying to fetch the messages inside of the email for general@futurefundsgroup.com): https://graph.microsoft.com/v1.0/users/futurefundsgroup@gmail.com/messages

However, when I do this, I get the following error on the Graph API tool (linked above):
User's image

Note that I have registered my application and have set the following API permissions: User's image

These are my authentication settings (not really sure at all what this does or if this makes a different in my case):
User's image

And this is my Azure active directory. For it, I have created a new Azure account for the email "general@futurefundsgroup.com", and I invited it to the application in hopes that this would resolve my issue. But unfortunately, it did not:
User's image

I'm really out of ideas here. What could I do to have this work? Please note that I created the Azure application on a separate email, and then added futurefundsgroup@gmail.com to the Azure AD manually.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,302 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Yakun Huang-MSFT 2,185 Reputation points Microsoft Vendor
    2024-06-26T07:36:13.7166667+00:00

    Hi @Sacha Baniassad

    After you create a futurefundsgroup@gmail.com user in Azure, you need to grant the user MS 365 Licenses as well, as shown below:

    Screenshot 2024-06-26 152819

    And when accessing the user, it needs to pass the principal name or Object ID of the user, as shown in the figure below:

    Screenshot 2024-06-26 153125

    Hope this helps.

    If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.