Email backup

Email Backup: How to Keep Your Own Copy of Every Message

Updated 5 min read

On this page
  1. What a useful email backup should preserve
  2. Keep an updated copy with mailmd
  3. Keep a backup separate from the mailbox

Email services such as Gmail, Outlook, and iCloud keep messages on their servers so you can access them across devices. A separate backup stays under your control and gives you access to messages if you lose access to your mailbox or the service loses them.

To keep a local copy up to date, mailmd is a practical option. It copies messages from your mailbox into Markdown files on your computer and adds new mail each time you sync. Check which folders it includes, and back up the files separately. mailmd leaves spam and trash out by default. If you keep the only copy on one computer, you could lose it with that device.

What a useful email backup should preserve #

A backup should match what you need to keep. That might mean all ordinary mailbox messages, or it might also include spam, trash, attachments, and messages from every folder. Decide what belongs in the archive before relying on it.

A one-time export saves a snapshot of your mail from that point in time. For example, Microsoft Outlook can export mail to a .pst file, a data file that can be imported later. Microsoft’s export steps for classic Outlook are File > Open & Export > Import/Export, then Export to a file > Outlook Data File (.pst). Choose the folders and save the file. Microsoft says periodic backup of all old and new email is not automated; an export therefore needs to be repeated to include later messages. Importing a .pst file also requires classic Outlook, since new Outlook does not support that import. See Microsoft’s Outlook backup instructions and PST export details.

Gmail users can request a copy of their messages through Google Takeout. That export is a snapshot, so new messages need a later export. The Google Takeout instructions note that large exports can be split into multiple files and that download links expire. Save every part of the export somewhere secure.

Keep an updated copy with mailmd #

mailmd is a free, open-source command-line tool. It connects to mailboxes through IMAP, a standard for accessing email, and uses the Gmail API for Gmail and Microsoft Graph for Outlook.com and Microsoft 365. For those API connections, create your own OAuth app, which authorizes mailmd to access your account, in Google Cloud or Microsoft Entra. The command-line steps below work on Linux, macOS, and Windows in Git Bash.

To install and sync manually, run:

curl -fsSL https://raw.githubusercontent.com/vincentsch/mailmd/main/install.sh | sh

Then connect the account using the command that matches the mailbox:

mailmd connect imap --email you@example.com
mailmd connect gmail --client-secret client_secret.json
mailmd connect outlook --client-id <id>

Use the IMAP command for IMAP mailboxes, including Gmail with an app password. Many IMAP providers require an app password; mailmd indicates when one is needed. Use the Gmail command for the Gmail API, or the Outlook command for Outlook.com and Microsoft 365. After connecting, run:

mailmd sync

The files go in ~/mail/<account>. For a safe preview without connecting an account, mailmd demo writes sample messages.

Each message becomes a Markdown file with its email headers in a metadata section at the top of the file. HTML messages become readable Markdown, with links and tables preserved; tracking images and hidden preview text are dropped. Attachments are saved next to their messages, and folders and years become directories. The index.jsonl file lists messages for scripts. Add --keep-raw to save each original .eml file too.

A sync adds new mail and updates whether messages are marked as read or starred. If you stop a sync with Ctrl-C, mail already saved stays in the archive, and the next run continues. mailmd leaves messages in the mailbox unchanged; it never moves or deletes them. It opens folders in read-only mode and leaves mail's read status unchanged. At login, it requests read-only access.

The archive keeps files for messages later deleted from the server and marks those messages as deleted on the server. It does not delete files from the archive. Spam and trash are excluded by default, so check whether those folders belong in your backup. For Gmail over IMAP, mailmd syncs All Mail, which includes archived mail. Use --folder, --exclude, and --since to choose what to copy.

To keep the copy up to date, schedule mailmd sync --quiet with a scheduler such as cron, systemd, launchd, or Task Scheduler. Store the archive somewhere included in your regular backup, or keep another copy separately. Without another copy, the files remain at risk from device loss or damage.

mailmd does not provide its own search engine. Open the Markdown files in an editor or note app, search with rg or grep, or filter index.jsonl with jq. You can also keep the archive in Git or include it in a regular computer backup. Coding agents such as Claude Code or Codex can search the files with their normal tools, but content they read is sent to the agent’s model provider.

mailmd saves your mailbox login outside the archive, where only your user account can read it. The login is not encrypted. mailmd has no telemetry and does not run a mailmd server. Review these details before connecting an account, especially if the archive contains sensitive messages.

Keep a backup separate from the mailbox #

A local archive protects against losing access to messages in the online mailbox, but a single local copy still depends on the computer and its storage. Keep another copy on a separate drive or in a backup service, and protect access to both the archive and the storage account. If you encrypt a backup, keep the recovery key somewhere safe; losing it can make the files unrecoverable.

The archive also does not free space in your mailbox. If you want to reduce mailbox storage, first confirm that the messages and attachments you need are in your archive, then delete unwanted mail from the mailbox yourself. mailmd does not send mail or import messages back into an account.

For regulated or work email, a personal archive may not meet retention or legal-hold requirements. Federal employees, for example, must follow applicable agency recordkeeping rules; the GSA email retention policy describes requirements for GSA accounts. Follow your organization’s policy and legal guidance before deleting or relying on archived messages.

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.

More on email backup