A simple Python script to extract emails and attachments from .mbox files and optionally convert them into readable PDF documents.
- Extracts all emails from an
.mboxarchive - Saves individual emails as
.emlfiles (if you want to skip saving.emlfiles, use the--no-emlflag) - Extracts and saves attachments
- Converts emails to clean, human-readable PDF files (optional)
- Quiet mode for batch or automated processing
- Python 3.7 or higher
- The following Python packages:
pip install reportlab
python mbox_extractor.py --mbox path/to/file.mbox [options]| Argument | Description | Required |
|---|---|---|
--mbox |
Path to the .mbox file to extract |
✅ Yes |
--out |
Output directory for extracted files (default: extracted_emails) |
❌ No |
--pdf |
Generate readable PDF files for each email | ❌ No |
--no-eml |
Do not save individual .eml files |
❌ No |
--quiet |
Suppress output messages (silent mode) | ❌ No |
Extract all emails and attachments from inbox.mbox and generate PDFs:
python mbox_extractor.py --mbox inbox.mbox --pdfExtract emails only, without creating PDFs or saving .eml files:
python mbox_extractor.py --mbox archive.mbox --no-eml --quietIf not specified otherwise, the script creates this structure for each mail in the output directory, similar to:
0001_subject/
├── 0001.eml
├── 0001.pdf
├── attachment1.pdf
├── attachment2.jpg
└── ...
- The script uses Python’s standard
mailboxmodule to read.mboxarchives. - PDFs are generated only if the
--pdfflag is used. - When
--no-emlis enabled,.emlfiles are skipped but attachments and PDFs are still saved.
This project is released under the MIT License.