What would be the easiest way to take a Outlook pst file and export all of the emails into a MySQL database?
6 Answers
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.

- 1,530
- 1
- 11
- 9
-
1i love how simple this would appear to be but will it support attachments? – Sam Hamilton May 20 '09 at 00:58
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

- 5,672
- 3
- 27
- 25
Been there done that :)
Yea libpst + a 6 pack of coors light is your solution here :)
like Cheeso said, not rocket science. Dump in a big table, but what to do with the attachments is where I struggled a little. First iteration ended up dumping on disk and columnize the path to "stuff".
Iteration 2, set up a small Hadoop instance and loaded the whole shebang in Hbase. I had 600Gb of emails... little OCD but works great to this day :)

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

- 5,141
- 8
- 34
- 50
-
1this gives me an idea of going the long way round: pst -> google -> imap -> mysql – Sam Hamilton May 20 '09 at 00:59
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.