Java OutlookExpress Reader: Build a Simple OE Email Parser
This guide shows how to build a simple Java reader for Outlook Express (.dbx) files, extract messages, and parse basic fields (From, To, Subject, Date, Body). It focuses on a minimal, practical approach using an existing library for reading DBX format and simple Java code to process messages.
Overview
- Goal: Read Outlook Express .dbx files and extract messages programmatically in Java.
- Scope: Parse headers and plain-text body, save attachments (if available), and export messages to simple formats (EML or plain text).
- Assumptions: You’re working with legacy Outlook Express .dbx files (from Windows XP era). Use a modern JDK (11+).
Tools and libraries
- Java 11+ (JDK)
- dbx4j or Apache Tika (prefer dbx4j if available for direct DBX parsing). If dbx4j is unavailable, use a DBX-to-EML conversion tool externally and process EMLs with JavaMail.
- JavaMail (Jakarta Mail) for EML parsing
- Maven for dependency management
Maven dependencies
Include these in your pom.xml:
<dependencies>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>jakarta.mail</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>org.example</groupId>
<artifactId>dbx4j</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
High-level approach
- Open the .dbx file using a DBX library or convert .dbx to EML.
- Iterate messages stored in the DBX.
- For each message, extract headers and body.
- Save attachments and/or export the message to EML/plain text.
Example implementation (DBX library available)
The exact API depends on the DBX library. Pseudocode:
import com.example.dbx.DBXFile;
import com.example.dbx.DBXMessage;
public class DbxReader {
public static void main(String[] args) throws Exception {
File dbx = new File(“Inbox.dbx”);
DBXFile dbxFile = DBXFile.open(dbx);
int count = dbxFile.getMessageCount();
for (int i = 0; i < count; i++) {
DBXMessage msg = dbxFile.getMessage(i);
System.out.println(“From: “ + msg.getFrom());
System.out.println(“To: “ + msg.getTo());
System.out.println(“Subject: “ + msg.getSubject());
System.out.println(“Date: “ + msg.getDate());
System.out.println(“Body: “ + msg.getBodyText());
// Save attachments if present
msg.getAttachments().forEach(att -> att.saveTo(new File(“attachments”, att.getFilename())));
}
dbxFile.close();
}
}
Alternative: Convert DBX → EML then parse with Jakarta Mail
- Use an external tool to convert .dbx to .eml (many open-source tools exist).
- Parse EMLs in Java with Jakarta Mail:
import javax.mail.;
import javax.mail.internet.MimeMessage;
import java.io.;
public class EmlParser {
public static void parseEml(File emlFile) throws Exception {
Session s = Session.getDefaultInstance(System.getProperties(), null);
InputStream is = new FileInputStream(emlFile);
MimeMessage message = new MimeMessage(s, is);
System.out.println(“From: “ + message.getFrom()[0]);
System.out.println(“To: “ + message.getRecipients(Message.RecipientType.TO)[0]);
System.out.println(“Subject: “ + message.getSubject());
System.out.println(“Date: “ + message.getSentDate());
Object content = message.getContent();
if (content instanceof String) {
System.out.println(“Body: “ + content);
} else if (content instanceof Multipart) {
Multipart mp = (Multipart) content;
for (int i = 0; i < mp.getCount(); i++) {
BodyPart bp = mp.getBodyPart(i);
String disposition = bp.getDisposition();
if (disposition != null && disposition.equals(Part.ATTACHMENT)) {
InputStream in = bp.getInputStream();
File f = new File(“attachments”, bp.getFileName());
try (FileOutputStream out = new FileOutputStream(f)) {
in.transferTo(out);
}
} else {
System.out.println(“Part: “ + bp.getContent());
}
}
}
}
}
Tips and caveats
- DBX is proprietary and fragmented; library support is limited. Converting DBX → EML externally is often simpler.
- Many DBX files are corrupted from old systems; always work on copies.
- Charset and encoding issues can affect message bodies—handle common encodings (UTF-8, ISO-8859-1).
- Attachments in DBX may be nested; recursively traverse multiparts.
Next steps
- If you want, I can:
- Provide a concrete Maven pom.xml,
- Show a complete working example using a specific DBX library,
- Or give a script to batch-convert DBX to EML.