Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 768
Corey Larson Avatar asked Jun 29 '16 15:06

Corey Larson


People also ask

How do I extract email headers in Outlook?

Double-click an email message to open it outside of the Reading Pane. Click File > Properties. Header information appears in the Internet headers box. Tip: You can highlight the information in that box, press Ctrl+C to copy, and paste it into Notepad or Word to see the entire header at once.

How do I get header information in OWA?

With the email open in which you'd like to view the headers, click on the more actions drop down arrow in the top right corner, then select View Message Details.

How do I access metadata in an email?

Once you have an email message open in Gmail, click on the three-dot icon in the top-right hand corner of the message to expand the More menu. Click on Show original to see the raw email message with its full contents and header revealed.

How do I read email headers in exchange?

Office 365 / Outlook Web Access (OWA) / Exchange 2016 In Outlook Web Access or Exchange 2016, in the email for which you want to view headers, click the down arrow. This icon is located next to Reply or Reply all in the upper-right corner. Click View message details. Review the email header information that appears.


1 Answers

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')
like image 187
Jason Johnston Avatar answered Oct 08 '22 09:10

Jason Johnston