What Is an MBOX File?
With mailmd How to Delete a Gmail Account Without Losing Your EmailsOn this page
If you exported email or found a file ending in .mbox, you have a mailbox archive that stores multiple email messages in sequence. Each message has headers, such as the sender and subject, and a body. Attachments are usually encoded inside the message.
Email programs use MBOX files to store or transfer mail. The format has several variations, so a file created by one program may not work perfectly in another. The .mbox extension is common, but the format does not require it.
How an MBOX file stores messages #
An MBOX file is a text file organized into lines. A separator line marks the start of each message, followed by the email’s contents. The separator often begins with From and includes sender and date information. That line is separate from the message’s ordinary From: header.
Attachments usually appear as encoded text rather than as separate files. This lets an MBOX file contain email with images or other binary attachments while keeping the message in a text-based format. The National Archives’ MBOX description notes that attachments are typically Base64 encoded.
MBOX has no single authoritative format specification. RFC 4155 describes a default format, but also explains that email tools have used different separator lines and other conventions. These differences mean email programs can read the same MBOX file differently.
Why MBOX files have variations #
MBOX versions mark where one message ends and the next begins in different ways. A message body might itself contain a line beginning with From . Some versions add a > character to such lines so an email program does not mistake them for the start of a new message. Other versions use a Content-Length header to mark how many bytes belong to a message.
The Arch Linux mbox manual describes schemes including MBOXO, MBOXRD, and MBOXCL. When you import an archive, the email program must recognize its format. If it expects a different format, it can mistake where messages begin or read the body text incorrectly.
How to open or use an MBOX file #
Open an MBOX file with an email client that supports MBOX, or import it into a mailbox in that client. An email client displays messages in an easier-to-read format. A text editor shows the raw message text and encoded attachment data. If you only need to inspect the file, a text editor can help, but it will not present the archive as a normal inbox.
Before importing an archive or changing its format, keep an unchanged copy of the original. Then test the import with the email program you plan to use. Check that the messages appear as expected, including their dates and attachments. MBOX files do not always transfer cleanly between programs because their internal conventions vary.
What to watch for #
MBOX files can be large, and some email software has limitations when writing them. For example, Dovecot’s documentation describes the risk of an interruption while modifying an MBOX file, along with limits involving payloads approaching 4 GB in that implementation. Keep a separate copy when working with important mail.
Treat an MBOX file like any other mailbox archive: it may contain private messages, attachments, and account information. Store it somewhere appropriate and avoid uploading it to a service unless you trust how that service handles the contents.
Free and open source
Try mailmd
mailmd is a free command-line tool that copies your email into Markdown files on your computer, one file per message. It works with any IMAP mailbox, and with Gmail and Outlook through their own APIs.
Install
$ curl -fsSL https://raw.githubusercontent.com/vincentsch/mailmd/main/install.sh | sh
Set it up with your coding agent
Set up mailmd so you can read my email. Use https://github.com/vincentsch/mailmd: read its AGENTS.md and follow the steps. Connect my mailbox and run the first sync. Then show me where the files are.