如何用Python将MBOX文件转换为单个EML文件?
Absolutely, converting your Gmail-exported MBOX file (which is indeed just a bundled collection of EML-style messages) into separate EML files is totally achievable with small apps or simple scripts—no need to immediately jump to paid tools unless you prioritize pure convenience. Here are your best options:
Option 1: Python Script (Free, Customizable)
Since you haven’t written code yet, a basic Python script is a fantastic starting point. Python’s built-in mailbox module lets you parse the MBOX and extract each message as an EML file without any extra installs.
Here’s a minimal, ready-to-use example:
import mailbox import os # Update these paths to match your file mbox_file = "path/to/your/gmail_export.mbox" output_folder = "extracted_emails" # Create output folder if it doesn't exist os.makedirs(output_folder, exist_ok=True) # Parse the MBOX and save each message as EML with mailbox.mbox(mbox_file) as mbox: for index, msg in enumerate(mbox, start=1): eml_filename = f"email_{index}.eml" full_path = os.path.join(output_folder, eml_filename) with open(full_path, "w", encoding="utf-8") as eml_file: eml_file.write(msg.as_string()) print(f"Done! Extracted {len(mbox)} EML files to {output_folder}")
Just swap in your actual MBOX file path, run the script, and you’ll get all individual EMLs in the output folder. You can tweak this later if you need to filter messages (e.g., by date or sender) too.
Option 2: Desktop Small Apps (No Coding Required)
If coding isn’t your vibe, there are free, lightweight desktop tools that handle this with zero setup:
- Thunderbird: The open-source email client can import MBOX files directly. Once imported, select all messages, right-click, and pick "Save As" to export them as individual EMLs. It’s a bit manual but totally reliable and free.
- Open-source MBOX converters: There are small standalone apps (like MBOX Viewer or Free MBOX to EML Converter) that let you load your MBOX and batch-export to EML. Just stick to trusted sources to avoid malware.
Option 3: Paid Online Tools (Convenience First)
If you’re short on time or don’t want to mess with setup, paid online tools are a valid choice. Look for services that specialize in MBOX to EML conversion—most let you upload your MBOX, process it, and download a zip of all EMLs. Just double-check the service’s privacy policy before uploading sensitive email data.
Quick Reminder
You’re spot-on about MBOX being a bundle of EML messages, so extracting them is a straightforward process—no complex magic involved. For Gmail exports, all key metadata should carry over seamlessly with any of these methods.
内容的提问来源于stack exchange,提问作者Sergio




