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.
Request.Credentials = CredentialCache.DefaultCredentials;
Request.Method = "GET";
Response = (HttpWebResponse)Request.GetResponse();
ResponseStream = Response.GetResponseStream();
sr = new StreamReader(ResponseStream, Encoding.UTF8);
s = sr.ReadToEnd();
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
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.
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.