How can I fetch emails from shared email address (or inbox) through an app or through Graph API?

Anirban Das 25 Reputation points
2023-03-03T05:53:50.8+00:00

I have a registered application in Azure portal which helps in fetching emails from a mail address. The application has all API permissions related to mail set to read and write permissions. The steps I follow to fetch emails are:

  1. I call https://login.microsoft.com/{org-id}/oauth2/v2.0/token with the application client id and client secret to get the refresh token & access token
  2. I use the above tokens to invoke graph API https://graph.microsoft.com/v1.0/me/messages along with filter parameters to fetch emails.

All these above actions are done through a backend service running on NodeJS, and whenever we sent email to that particular mail address (say, email address removed for privacy reasons), the backend service invokes above APIs to return emails from email address removed for privacy reasons.

Now, I have another shared mailbox (say, email address removed for privacy reasons) and I want to use the application to fetch emails from that inbox as well. I already had done few workarounds, but none has worked.

  1. I changed the URL to https://graph.microsoft.com/v1.0/users/{id | shared mailbox address}/messages but I keep getting Access denied error.
  2. I have already given all Shared consent API permissions of the application.

Appreciate any help.

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

Accepted answer
  1. CarlZhao-MSFT 36,571 Reputation points
    2023-03-03T08:54:11.5233333+00:00

    Hi @Anirban Das

    Make sure that you are granting the Mail.ReadWrite application permission and not the delegated permission. After granting permissions, you need to acquire a token using the daemon-based client credentials flow.

    User's image

    Call the graph API endpoint:

    User's image

    Also, make sure that the application permissions are not restricted by the administrator to only specific Exchange Online mailboxes, or you will still receive this error.

    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.

    1 person found this answer helpful.

7 additional answers

Sort by: Most helpful
  1. Manu Philip 16,961 Reputation points MVP
    2023-03-03T06:02:52.8466667+00:00

    I have published an article in my blog to connect Office 365 mailbox through Graph API as below:

    Create Custom Folder in Exchange Online Mailboxes using Graph API using Windows PowerShell

    It's not describing the exact requirement you have. Have a look and see if it helps to resolve some of the issues


    --please don't forget to upvote and Accept as answer if the reply is helpful--

    0 comments No comments

  2. salteood 0 Reputation points
    2023-04-01T20:03:15.7466667+00:00

    To fetch emails from a shared email address or inbox through an app or Graph API, you will need to authenticate your app with the appropriate permissions and use the relevant API endpoints to access the mailbox data.

    For example, using the Microsoft Graph API, you could use the List Messages endpoint to retrieve a list of messages in a shared mailbox or inbox, and the Get Message endpoint to retrieve the contents of a specific message.

    To use the Graph API or any other email-fetching method, you will need to ensure that you have the necessary permissions and authentication set up to access the shared mailbox or inbox.

    As an analogy, this process is similar to are identical twins height same height, but still have individual identities and may require different methods to access their personal information.

    0 comments No comments

  3. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  4. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more