Using the Exchange 2007 Web Service for Mail retrieval…


So here’s the problem I had: There is an Exchange 2007 server I am forced to use for some of my daily work and that’s where the problems start: Due to the work of some evil geniuses there’s a load of user and security policies associated with that server. That’s not a problem per se: It’s just that things like “forward all mails to this account” don’t work. You have to use Outlook Web Access or the heavyweight Outlook to get to your mails… Till today I had an Outlook 2007 running on my private IMAP mailserver machine just for the purpose of downloading all the mail from the Exchange server to the local harddisk. I had setup a client-rule to copy all the mail to my IMAP server but despite the fact Outlook is running on the exact same machine as the IMAP server it just did not work for more than 1-20 messages… connections were lost and stuff screwed up. So I had to move all the messages manually (Select-All -> Drag-n-Drop onto the IMAP folder inside Outlook) which took me quite some time each month.

Two days ago I read an article where namenlos wrote about his journey with his employers Exchange server. He wrote a Python script that did the job for Exchange 2003 by using the WebDAV features. These features unfortunatly are deprecated in the current 2007 release of Exchange. So I decided to write a tool in C# that does the trick and uses the brand-spanking new Exchange 2007 Web Service.

The Exchange 2007 SDK is a wasteland to say the least when it comes to documentation. It took me some time and a good search engine to get to something useful out of it. But I think it’s worth the pain: When you got over the first annoying steps you’ll just like me will start to love the possibilities this Web Services give you.

In my case I am using the webservices to do these things:

  1. allocate my inbox and obtain a listing of messageIDs
  2. get the complete messages out of my inbox
  3. reformat the messages and send them via smtp to my own mail server

What I’ve written is not feature complete (as in: no attachements, …) but it’s a great and working start and does the 3 point-trick from above quite well. I will refine the code and add the missing features (e.g. attachements and stuff) in the future… or maybe you are faster than me. In that case it would be well appreciated if you send me your code/a link to the code (find my email in the sourcefile…)

get the code here. (90 kbytes)

Source 1:
Source 2:
Source 3:

Comments are closed.