Retrieving the headers of an e-mail message

When troubleshooting mail flow issues, you may need to take a look at the headers of an e-mail message. This is easy to do through Outlook for items in your own mailbox, but if you want to do this on behalf of another user, it requires you to have permissions to their mailbox, and then you need to open their mailbox in Outlook to view the headers. In this recipe, we'll take a look at how you can retrieve the headers of a message in your own mailbox, as well as another user's mailbox, using the EWS Managed API and PowerShell.

How to do it...

  1. First, load the assembly, create the ExchangeService object, and connect to EWS:
    Add-Type -Path C:\EWS\Microsoft.Exchange.WebServices.dll
    $svc = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService ...

Get Microsoft Exchange Server 2013 PowerShell Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.