Export and save email

How to Download All Attachments from Gmail

Updated 3 min read

On this page
  1. Download attachments from one Gmail message
  2. Save Gmail attachments with mailmd
  3. What a full Gmail export contains
  4. Check the local copy before deleting anything

Gmail’s Download all attachments option puts the files attached to one email in a ZIP file, a compressed file you open to get the attachments. To collect attachments from across a mailbox, use a different approach. Gmail’s export preserves messages and attachments, while mailmd copies messages to your computer and saves each attachment beside its message.

To keep a copy of Gmail messages and attachments on your computer in a format that is easy to browse, use mailmd. It is a free, open-source command-line tool, which you run by entering text commands. mailmd connects to Gmail, copies messages and attachments to your computer, and leaves your mailbox unchanged.

Download attachments from one Gmail message #

On a computer, open the message containing the files and select Download all attachments in the attachment area. Gmail saves the attachments in a ZIP file; open the ZIP and extract the files. Google’s help page also explains how to download a single attachment, and a Gmail community response describes the download-all option producing a ZIP.

Check each message in a conversation separately. A conversation, also called a thread, groups related emails. Using the download control on one message does not confirm that attachments from the other messages are included.

To find messages before downloading, search Gmail for has:attachment. Narrow the results with a sender or file type, such as has:attachment from:person@example.com or has:attachment filename:pdf. Gmail documents these and other search operators.

Save Gmail attachments with mailmd #

Use mailmd to collect attachments from many messages or keep a local copy up to date. mailmd saves each email as a Markdown file, a plain-text file with simple formatting, and saves its attachments beside it. It sorts files into folders by year, and index.jsonl lists messages for scripts.

To install and sync Gmail:

  1. Open a terminal. On Windows, use Git Bash.
  2. Install mailmd:
    curl -fsSL https://raw.githubusercontent.com/vincentsch/mailmd/main/install.sh | sh
  3. Connect a Gmail account through the Gmail API, Google's interface for tools that access Gmail:
    mailmd connect gmail --client-secret client_secret.json
    This method requires an OAuth app, a Google Cloud app that gives mailmd permission to access Gmail. You can also connect through IMAP, a method for accessing mailbox messages:
    mailmd connect imap --email you@example.com
    Gmail IMAP connections require an app password. mailmd prompts for credentials; type your password into mailmd rather than sharing it with another person or service.
  4. Copy the mailbox:
    mailmd sync

Mail is saved under ~/mail/<account>. The Gmail API and IMAP connections give mailmd read-only access: it can read messages but cannot mark them as read, move or delete them, or send messages. It leaves spam and trash out by default. For Gmail over IMAP, it syncs All Mail, which includes archived messages. The mailmd project documents additional options such as --folder, --exclude, and --since for choosing what to copy.

On later runs, mailmd adds new mail and updates which messages are marked read or starred. If you stop a run with Ctrl-C, saved files remain, and the next run continues. The local copy keeps files even if you later delete the messages from Gmail. mailmd also supports --keep-raw to save the original email file alongside the Markdown version.

What a full Gmail export contains #

Google Takeout is another way to export Gmail. Google says the export includes message content, headers, and attachments, but it gives you an archive of the mailbox rather than a folder of attachment files. After downloading the archive, extract its contents, then extract the attachments from the messages. See Google’s information on Gmail exports and downloading Google data.

Cloud files linked in an email are separate from files attached to it, so a Drive link does not mean the file itself is included in the message or an attachment collection. Confidential-mode messages can also prevent downloads. If a file is missing, check whether the message contains a link or uses confidential mode.

Check the local copy before deleting anything #

Open a few saved messages and attachments to confirm they are the files you expected. mailmd does not free Gmail storage on its own; deleting messages from the mailbox is a separate action. Keep the original messages until you have checked the local copy, especially if the files matter.

mailmd stores login information outside the local copy, where only your user account can read it. mailmd does not use a mailmd server or send telemetry. The archive itself is not a mail client, and mailmd does not import messages back into Gmail or convert them to PDF or PST.

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