tags:

views:

212

answers:

2

I need to write a single function which will take multiple eml files ( may be from a single filesystem folder ) and convert them to a single PST file.

Is it possible? if yes can someone provide a sample code?

I assume its possible because there are many commercial eml to pst converters out there doing this

+1  A: 

Might very well be easier or better ways but one way would probably be to use Interop to automate Outlook. There might be some ability to use the built in Import features of Outlook and that would be the first thing I'd try looking for. Assuming that that's not possible, you should still be able to do it by reading the eml files in your app and then creating the mail items via Interop.

Normally eml files are just text files in MIME format so that's just a matter of reading them in as text files and parsing them. Here's one article about parsing MIME from C# and otherwise just search for "POP3 C#" and you'll find other articles about that.

Then you use Outlook Interop from the namespace Microsoft.Office.Interop.Outlook as is described here.

At a guess I'd assume that you might have to first create an Application object, then use that to get the Store object (I think each PST file will be one Store) and then the Folder in there and then find some way to create the MailItem using the data you parsed from the eml file.

This article describes using Outlook automation to create contacts and appointments and could probably be useful.

ho1
A: 

You can find the specifications to the pst file format here. But I guess you would spend some time putting it all together to create a eml->pst parser yourself. But it should be possible.

Mikael Svenson