SharePoint 2007: Incoming email manipulation

 

Okay this one goes totally with no guranties… I had this kind of scenario where I needed to handle incoming emails in SharePoint and convert them to list items with custom modifications (setting fields right etc stuff). I did this by creating a workflow (with Visual Studio 2008 style) that fires "when item is created" on the list that serves as a staging list for incoming emails (there are reasons for this). Now when mail hits the list, workflow starts and creates a new list item in another list and does the magic between these two files.

Now that was not rocket science but here things get intresting. There are awful lot of situations where incoming email could be html formatted. And in my needs were to obtain body as a plaintext. Now ripping the html’s off from mail messages body is something that I would not like to do (guess what happens if there are some tags that should be in that email and my all mighty html tag cleaner takes those away.. yieppee another point to fix). 

Well I got this thing under control by using SharePoint utility namespace (Microsoft.SharePoint.Utilities) and from there I used class called SPEmailMessage. Now apparently this email message was not designed directly to be used in this way, in constructor this class takes in a Stream and envelopeSender (which might be the sender of a email message). I had to be a bit creative with this stream, so since I configured the incoming email settings with like "save original message as a attachment", creativity had a kick start. The attachment contains whole message with all the needed stuff, so just put this into stream and feed it to SPEmailMessage. Bueno.

This solution works with .mht and .eml messages (.mht comes with Outlook Web Access emails and .eml comes with Outlook, at least this I think). Feel free to comment or ask something about this. I do not know does this solution work in the long run but it gets the job done (okay getting the plain text body from SPEmailMessage ? There is a small property called .BodyAsPlainText which gets the mails body without html tags…). I hope that someone gets atleast creative thoughts from this…

Tags / Keywords:

SharePoint 2007, Windows SharePoint Services 3.0 (WSS 3.0), Microsoft Office SharePoint Server (MOSS), Incoming email, SPEmailMessage, Workflow 

Advertisements

About Sakarih

I am SharePoint developer/architect from Finland and my blogposts are all about SharePoint 2007/2010/2013 stuff. There might be also something else posted.
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s