How can I dump emails from an Outlook .pst file into a MySQL database?

15,805

Solution 1

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

Solution 2

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.

Solution 3

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
Share:
15,805
Sam Hamilton
Author by

Sam Hamilton

Updated on June 05, 2022

Comments

  • Sam Hamilton
    Sam Hamilton almost 2 years

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

  • Sam Hamilton
    Sam Hamilton almost 15 years
    i love how simple this would appear to be but will it support attachments?
  • Sam Hamilton
    Sam Hamilton almost 15 years
    this gives me an idea of going the long way round: pst -> google -> imap -> mysql