Paul Andrew

Technical Product Manager for Office 365 at Microsoft

Handling My Email In .NET Code

Handling My Email In .NET Code

  • Comments 3

I was thinking about improving some of my email inbox processing recently and I spent some time refreshing my memory on email processing from .NET.  I wanted to be able to grab a whole lot of emails from my inbox that met certain criteria and extract information from them into Excel.  I could have got this wrong but here's what I found.

I started off trying to work with WebDAV.  And I found a support article which led me to write this code snippet to retrieve an email.

Request = (System.Net.HttpWebRequest)HttpWebRequest.Create(“http://email-server/Exchange/account/Inbox/EmailSubject.EML“);
Request.Credentials = CredentialCache.DefaultCredentials;
Request.Method = "GET";
Request.Headers.Add("Translate", "f");
Response = (HttpWebResponse)Request.GetResponse();
ResponseStream = Response.GetResponseStream();
sr =
new StreamReader(ResponseStream, Encoding.UTF8);
s = sr.ReadToEnd();
Console.WriteLine(s);

I could get listings of email folders from WebDAV using this and I could retrieve a whole email.  I found that I had to use regular expressions to parse them out of the headers and this wasn't what I had intended to do.  I wanted to get the sender and any flags as properties without having to parse them myself.  So next, I looked at CDO and MAPI but I came across this support article which stopped me in that investigation.

813349 Support Policy for Microsoft Exchange APIs with .NET Framework
http://support.microsoft.com/?id=813349

Next, I found SlipStick Systems email developers portal from which I learnt plenty.  And it gave me the idea to use the Outlook Add-ins API.  They had a link to this article from which I wrote code that could browse my email inbox and get the properties out that I wanted.  Here's the article that I used successfully.

http://support.microsoft.com/?kbid=313795

Also at SlipStick there's a neat Outlook Add-In called TODI that let's you extract email attachments to your hard disk, replacing them in the email with a link. 

  • The Outlook Object Model & Add-ins capability is fantastic (as is the developer portal you mention, one of my first resources for outlook/exchange issues as well), I find myself writing little 10 line functions to perform odd jobs all the time. By the way... it's slipstick, not slapstick :-)
  • I fixed the typo :-)
  • need email code
Page 1 of 1 (3 items)