Exporting Outlook mail messages


Matti Mattila wrote for us A musician story. He is back with a new article, this time a technology topic that I’m sure will interest many of you.

Exporting Outlook mail messages

I ran into a whole new problem a week ago when my six years old computer stopped working. The “Old Faithful” had served me for years, but now she finally wanted to get retired. Well, that was something she certainly had deserved after all these precious moments. I now look her sadly kicking her heels on the floor and waiting for a new life as spare parts somewhere else. The new and energetic beauty hums silently and dignified on my desk at the very same place the Old Lady was sitting before only a few days ago.

She runs on Windows Vista, which is quite a beauty but not a beast. The old wrinkly ran Windows XP, but already showed exhaustion under the too heavy workload. Now everything is changed, even my mail application turned from Outlook 2000 into a brand new Windows Mail.

Shifting from XP to Vista raised a bunch of new and unpredictable problems to solve. First of all was my new mail client. It works like a charm and that’s why I wanted to move my six-years-old email message archive from Outlook to this new client, but everything didn’t go as planned. Windows Mail could not interact with Outlook 2000 despite I set Outlook as my default mail client. This path came to its dead-end and I needed completely new approach.

My programming background was a relief as I understood that I can write a small VBA script to rescue my old messages. After thorough investigation I decided to individually save each mail message as an eml file. This format is widely understood by many different mail clients, so it was an excellent choice.

Unfortunately native Outlook 2000 lacks ability to export in eml format. Actually the format follows strictly RFC 822 specification, so writing such a script wouldn’t be too complicated. But I waited a second before rushing to code.

A quick search with my favorite search engine gave me pain relief. I found an Outlook Redemption library on the net, which would answer all my questions exporting messages from Outlook PST storage as single files. Redemption object library gives new functions thus expanding the basic Outlook object model. One of these important functions is saving a message as RFC 822 format. This is exactly what I was looking for, so writing a short script was merely whistling and wheeling.

First we need to download the Redemption object library. It’s free for development purposes and this would be enough for our sample. The second stage is unpacking the zipped file. After that the installation is just registering the library in the command prompt as follows:

regsvr32.exe C:[full path]redemption.dll

The example above assumes that you unzip the package on your hard disk in a folder you specify replacing [full path] placeholder. Finally, we need to make a reference to this library in Outlook Visual Basic editor. To do so, select Tools / References and tick the checkbox next to Redemption Outlook Library. All the objects will be exposed to the project as soon as you click OK. The following code snippet shows the basic idea on how to save the first message in Inbox as test.eml file.

Dim o As Redemption.SafeMailItem
dim i As Outlook.Explorer
Set i = ThisOutlookSession.Explorers.Item(1).Explorer
Set o = CreateObject(“Redemption.SafeMailItem”)

o.Item = i.CurrentFolder.Items.Item(1)
o.SaveAs “test.eml”, Redemption.rdoSaveAsType.olRFC822
Set o = Nothing
Set i = Nothing

Knitting the rest of the code should be relatively easy. A loop would do the most of the task while it recursively loops through the messages in Outlook folders. Each mail item is saved with unique name on the disk. Restoring these messages to Windows Mail is just dragging and dropping the files into the appropriate folders. So, thanks to Redemption for giving me these great tools to export my Outlook mail message into Windows Mail.

  • CommentLuv badge


    This blog uses CommentLuv technology. It allows you to put your keywords with your name. To complete this, you need approved at least one comment. Use your real name and then @ your keywords (maximum of 3)