Is it possible to retrieve the RFC 2822 (or any) headers from an email with the Outlook/Office 365 REST API?
Asked Answered
S

2

5

An application I am working on needs access to the headers of an email - specifically ones like return-path, in-reply-to, and references. Ideally, we would love to be able to access all of the RFC 2822 headers of the email. Is this possible with the Outlook/Office 365 REST API? If not, is it possible with any API?

Sundry answered 29/6, 2016 at 15:2 Comment(0)
C
9

UPDATE: The InternetMessageHeaders property was added to the beta endpoint of the Outlook API, so you can get this without using the extended property stuff. You do have to request the property explicitly via $select though. Something like:

GET https://outlook.office.com/api/beta/me/mailfolders/inbox/messages?
$select=Subject,InternetMessageHeaders

For Graph: The property also exists on messages in the beta endpoint for Graph, so you can do:

GET https://graph.microsoft.com/beta/me/mailfolders/inbox/messages?
    $select=subject,internetMessageHeaders

For non-beta endpoints: The API doesn't directly provide access. However, you can access the PidTagTransportMessageHeaders MAPI property using the Extended Property API.

From the first link, we see that the property ID for PidTagTransportMessageHeaders is 0x7D, and the type is String. So the $expand parameter of your GET would look like:

$expand=SingleValueExtendedProperties($filter=PropertyId eq 'String 0x7D')

NOTE: This is only applicable for the Outlook endpoint (https://outlook.office.com). For Graph, see the answer from madsheep

Putting that together with a GET for a specific message, your request might look like:

GET https://outlook.office.com/api/v2.0/me/messages/{message-id}?
$select=Subject,SingleValueExtendedProperties
&$expand=SingleValueExtendedProperties($filter=PropertyId eq 'String 0x7D')
Cotillion answered 29/6, 2016 at 15:24 Comment(2)
Are you able to do that with multiple properties? How would that look? Say i wanted PidTagTransportMessageHeaders and PidTagAutoForwarded headersHosey
Yes you can. You would combine the property tests in the $filter with an or clause: $filter=PropertyId eq 'String 0x7D' or PropertyId eq 'Boolean 0x5'.Cotillion
S
5

To all the poor souls lost in the insanties of MS Graph api - the answer above doesn't seem to be correct anymore as it will return error "PropertyId is not a property name" - it seems the correct answer now is:

GET https://graph.microsoft.com/beta/me/messages/{message-id}?
$select=Subject,SingleValueExtendedProperties&
$expand=SingleValueExtendedProperties($filter=id eq 'String 0x7D')

This is how you get the message headers from the Outlook/Office 365 REST Graph api.

Sartor answered 5/10, 2017 at 15:6 Comment(2)
It looks like you are using the beta API? Is this also true with the v2.0 API?Sundry
Just to clarify: The answer is still correct for the Outlook endpoint. Graph changed the name from "PropertyId" to "id" inside the SingleValueExtendedProperty type, which is why you have to adjust between the two API endpoints.Cotillion

© 2022 - 2024 — McMap. All rights reserved.