Using EWS (Exchange Web Services) to read email subjects.

Today I had a discussion with a vendor, they are delivering a solution that reads email from a specific email account on Exchange, and create a ticket in our helpdesk system. Often the email subjects shows up mangled in the helpdesk system, and the particular vendor blames Exchange EWS for not messing up the data.. I had a hard time believing that, so I set out to prove it is not Exchange that is a fault.

First off I needed to download Exchange EWS, which is a separate download from Microsoft.

So just download and install the MSI file.

Then it is time to fire up PowerShell, first thing we need to do is load the EWS assembly

Then we need to specify a username, Password, domain and the mailbox that we want to look at. There are several ways to do this, the simplest way is just writing this in clear text.

Or you could query for it:

Then we have to create a EWS Exchange object.

Possible options for ExchangeService types are Exchange2007_SP1, Exchange2010, Exchange2010_SP1 or Exchange2010_SP2.

Then we have to pass credentials to the $EWS objects depending on how we chose to supply the password initially, we have 2 options again.

Here is the way if we supplied the information in clear text

Here is the way if we prompt for the username/password with Get-Credential

Then we use the AutoDiscoverURL method to look up the Exchange Server URL endpoint.

In this example we will iterate through the inbox and list the first 20 items and output the subjects.

Here is the script in its entirety.

After analyzing the output from Exchange many times, I am convinced that the vendor is mistaken when he claims Exchange is screwing up the data.