Recursive AI

Read Outlook Express DBX email in C#

OneMail is a free, open-source email library for .NET from Recursive AI. MIT or Apache-2.0, no native dependencies.

Stream the live messages in the zip’s sample Inbox.dbx to .eml files with DbxReader.

Terminal
dotnet add package RecursiveAI.OneMail

Requires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.

C#
using RecursiveAI.OneMail.Sources;
using RecursiveAI.OneMail.Stores.Dbx;
 
using var source = FileSource.Open("Inbox.dbx");
var folder = new DbxReader(source);
if (folder.Kind != DbxFileKind.MessageDatabase)
    throw new InvalidDataException("Expected a DBX message database.");
int number = 0;
foreach (var entry in folder.EnumerateMessages())
{
    if (!entry.HasMessage)
        continue;
    using var message = folder.OpenMessage(entry);
    string name = $"message-{++number}.eml";
    using var output = File.Open(name, FileMode.CreateNew);
    message.CopyTo(output);
    Console.WriteLine($"{name}: {output.Length} bytes");
}

Paste the code above into Program.cs of a new dotnet new console project and dotnet run, or unzip the example and dotnet run.

Text
message-1.eml: 77 bytes
message-2.eml: 81 bytes

Here’s the first of the two messages in the sample Inbox.dbx, shown as email text:

Text
From: lee@example.com
To: sam@example.com
Subject: Hello
 
First sample.

The program rejects Folders.dbx because it isn’t a message database. Run it in a fresh output directory with the input file there, or remove your previous exports before running it again: FileMode.CreateNew won’t overwrite them.

Variations

List original subjects without writing files. With folder opened as above, read the indexed subject before opening any message stream:

C#
foreach (var entry in folder.EnumerateMessages())
    Console.WriteLine(entry.OriginalSubject);
Text
Hello
Reminder

The short answer

Use DbxReader.EnumerateMessages() on a message folder such as Inbox.dbx. For each entry with HasMessage set, copy OpenMessage(entry) to a separate .eml file. The stream supplies the stored message bytes, so no text decoding or message reserialization is needed. This reads live entries; it doesn’t recover deleted emails.

How do I get my emails from Outlook Express?

Start with a copy of the DBX for the folder you want to export. Inbox.dbx is one message database, not the whole mail store. Folders.dbx contains records about the folder hierarchy rather than the messages. Repeat the extraction for each message database you want. Use a separate output directory for each folder, since the sequence numbers are local to a run.

How do I convert DBX to EML without changing the message?

A message’s bytes may be stored in several pieces. OpenMessage follows the chain and exposes its contents as a forward-only stream, without loading the whole email at once. Keep the DBX source open until those streams are closed and copy the stream directly to the output. That preserves the stored headers and body bytes, including any MIME-encoded attachments already in the message. Outlook Express’s folder flags and indexed fields are not part of that stream; keep the DBX if you also need the folder metadata.

Can you recover deleted messages from a DBX file?

Not by enumerating the live index. Outlook Express removes a deleted message’s entry from that index. A live record can also exist without a text chain, for example if only the header was downloaded; the example skips these entries. Deleted-message recovery is a separate operation, and some bytes may be missing or overwritten. See the DBX recovery notes for what it can and can’t retrieve.

All onemail recipes