views:

861

answers:

5

What would be the easiest way to take a Outlook pst file and export all of the emails into a MySQL database?

+5  A: 

Yikes. Probably the easiest would be to open your PST in Outlook, and use

File->Import and Export, Export to a File, Comma Seperated Values (Windows)

This creates a CSV file, which you can then pull into MySQL via mysqlimport.

If you need more information besides just the contents of the messages, you will need to tap into the store directly through various exotic means.

Robby Slaughter
i love how simple this would appear to be but will it support attachments?
Sam Hamilton
A: 

I don't know the answer, but, if you take a look at Google email uploader (open source), they do the reading part...

Ali Shafai
this gives me an idea of going the long way round: pst -> google -> imap -> mysql
Sam Hamilton
A: 

I would write an automation client in C# to iterate through the outlook emails, then upload each one to your database. None of this stuff is rocket science. The automation client requires Outlook to be installed and running on the machine. In other words, this approach does not involve just "reading" the PST ; automation implies the Outlook app is actually running and your code is asking the app to open the emails individually. (You need not display all the UI as you do this).

Here's a Q on how to read a PST file by automating outlook using C#. Starting with that, you then need to add the MySQL update stuff, and some good error handling. Be sure to test thoroughly before deleting the files from Outlook. If you choose to not delete, be sure to have a good indexing approach to insure idempotence.

Cheeso
A: 

Powershell could be good for this? Eg enum emails in a folder, create sql insert for each, append insert to batch sql script:

$olApp = New-Object -com Outlook.Application
$namespace = $olApp.GetNamespace("MAPI")
$folder = $namespace.GetDefaultFolder(1)
$folder.Items  | %{ 
    "insert into MyTable (MyCol1, MyCol2, etc) values ($_.Subject, $_.body, etc)"
} | out-file "outfile.sql" -Append
Seba Illingworth
A: 

A solution I just stumbled across is: libpst

Obviously there is still some plumbing in processing one of the converted formats into SQL, but if importing into Outlook and then exporting as CSV is not an option, libpst would be a good alternative.

TK