How to get a message using Graph from a mailbox using data in an email header

Sounds Essential 0 Reputation points
2024-09-17T18:25:41.45+00:00

I want to use the details found when you view an email message as source (headers, spam results, body content etc) to ping the Graph API to retrieve certain details of the message. This would be done with an app that has application permissions. It would be great if the message headers had the Exchange ID in them so I could simply use:

https://graph.microsoft.com/v1.0/users/test@test.com/messages/{message_id}

But it doesn't. I have tried:

https://graph.microsoft.com/v1.0/users/test@test.com/messages?$filter=internetMessageId eq '{the url encoded internet message id}'

And that returns an empty array. That query would be flawed anyway as multiple messages could have the same internetMessageID.

Is what I'm attempting to do (ping API with some info from the email headers) possible? Many thanks.

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

1 answer

Sort by: Most helpful
  1. Rohit Raghuwanshi - MSFT 240 Reputation points Microsoft Vendor
    2024-09-19T05:43:25.1033333+00:00

    Hi Sounds Essential,

    Thank you for reaching out, Microsoft!

    I tried to fetch the email using Graph API with the data that is available in email header and was successfully able to retrieve an email using internetMessageId. Additionally internetMessageId is an unique identifier for an email and return more than one response only when same message is present in more than one folders. Please refer attached screenshot.

    User's image

    Also, to fetch email from particular folder you can use GET /me/mailFolders/{id}/messages. Please refer the below doc for more details:

    https://video2.skills-academy.com/en-us/graph/api/user-list-messages?view=graph-rest-1.0&tabs=http

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


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.