Export and save email

How to Download Emails from Gmail

Updated 3 min read

On this page
  1. Download one Gmail message
  2. Save a local Gmail archive with mailmd
  3. When to use Gmail’s mailbox export

To save one Gmail message, use Gmail’s Download message command. For a readable local copy of your mailbox that you can update over time, mailmd is the best fit. It saves email as Markdown files, a plain-text format you can open in editors and note-taking apps. Gmail also offers a mailbox export in MBOX format, a file format for storing email messages.

The right choice depends on what you need: a single email file, a local collection you can search, or a printable copy. The steps below cover Gmail’s built-in download and how to set up mailmd for a local archive.

Download one Gmail message #

On a computer, open the message, select the three-dot More menu beside the reply icon, then choose Download message. Gmail saves the message as an .eml file, which a compatible email program can open. The Gmail instructions for downloading messages describe this command. Use the message-level menu, since Gmail has other three-dot menus in the same view.

An .eml file keeps the message as email, including its content and attachments. For a printable document, use Gmail’s Print command and choose Save as PDF in the browser’s print window. A PDF is convenient to read or print, but it is not a full mailbox archive. See Gmail’s printing instructions.

Save a local Gmail archive with mailmd #

mailmd is a free, open-source command-line tool. A command-line tool runs when you enter instructions in a terminal. It saves each message as a Markdown file in a folder on your computer. Unlike a one-time download, you can run mailmd again to add new messages.

Install mailmd in a terminal, then connect Gmail and sync:

curl -fsSL https://raw.githubusercontent.com/vincentsch/mailmd/main/install.sh | sh
mailmd connect gmail --client-secret client_secret.json
mailmd sync

The Gmail API connection requires an app you create in Google Cloud. The app uses OAuth, a sign-in method that grants specific access to an account after you sign in. mailmd requests permission to read your Gmail. If you prefer Gmail over IMAP, a standard for accessing email from other programs, connect with an app password instead:

mailmd connect imap --email you@example.com
mailmd sync

Some IMAP providers require an app password; mailmd indicates when one is needed. Gmail’s archived messages are included through All Mail. Spam and Trash are excluded by default.

Mail goes into ~/mail/<account>. Each file starts with the message headers, which show details such as the sender and date. mailmd turns HTML email into readable Markdown and saves attachments beside each message. It uses directories for folders and years. To keep the original email file as well, add --keep-raw to the sync command.

mailmd opens folders in read-only mode. It does not mark messages as read or move them. It also does not delete messages or send mail. mailmd never removes files from the local archive. If a message is later deleted from Gmail, its local file stays in the archive and remains marked as deleted on the server. A later sync adds new messages and updates each message’s read and starred status. For the installation details, see the mailmd project instructions.

The archive is stored on your computer, so it does not free space in Gmail. mailmd also does not import messages back into Gmail or act as an email client. You can search the saved files with an editor or tools such as grep; back up the archive like other files on your computer.

When to use Gmail’s mailbox export #

Gmail’s Google Takeout export creates an MBOX archive, which is useful when you need a conventional email export. Google documents the contents and limits of Gmail exports. The downloaded archive must be opened with a program that supports MBOX. For a plain-text collection that is straightforward to inspect and keep updating, use mailmd instead.

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 export and save email