Email backup

How to Back Up iCloud Mail

Updated 3 min read

On this page
  1. Why iCloud Mail needs a separate backup
  2. Back up iCloud Mail with mailmd
  3. Keep the backup current and protected
  4. Check the copy before relying on it

iCloud Mail stores messages on Apple’s servers and keeps connected devices in sync. When devices sync, deleting a message on one device also deletes it on the others. An independent backup is a separate copy that you control.

Apple says iCloud Backup does not include mail messages. To keep a portable copy on your computer, use mailmd. It saves each message as a readable Markdown file in a folder you can include in your regular computer backup.

Why iCloud Mail needs a separate backup #

A device backup does not preserve earlier versions of your mailbox. When you restore an iPhone or iPad, it reconnects to the mail provider and retrieves the messages still available there. Likewise, iCloud’s Archive folder organizes messages but does not create a separate backup.

mailmd connects to an email account using IMAP, a standard way for email programs to read messages from a mail server and keep them in sync. Apple supports IMAP for iCloud Mail and publishes its server and sign-in settings.

Back up iCloud Mail with mailmd #

mailmd is a free, open-source command-line tool. A command-line tool runs by entering text commands in a terminal. mailmd saves messages in folders on your computer, with one Markdown file for each message. Its website and source code provide installation and setup details.

On macOS or Linux, install it from a terminal:

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

On Windows, use Git Bash. Then connect your iCloud account and start the first copy:

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

Enter your iCloud email address in place of you@example.com. If mailmd requests a password, use an app-specific password when required. Apple describes how to create an app-specific password, which is a separate credential for an email program. Enter the password in mailmd yourself.

mailmd saves the messages under ~/mail/<account>. It creates directories for folders and years, and stores attachments beside their messages. mailmd turns HTML messages into readable Markdown. It puts message headers in frontmatter, a block of information at the top of each file. To keep each original message as an .eml file too, run:

mailmd sync --keep-raw

mailmd opens mail folders in read-only mode and requests read access. It does not mark messages as read, move or delete them, or send mail. Spam and trash are excluded unless requested. The archive keeps files even when messages are later deleted from the server, marking those messages as deleted on the server.

Keep the backup current and protected #

Run mailmd sync again to copy new mail and update read and starred marks. To keep the archive current, schedule mailmd sync --quiet with a scheduler such as cron, launchd, or Task Scheduler.

mailmd never deletes files from the archive. Back up the archive folder separately using your computer’s backup method or another copy of your files. mailmd does not have its own search engine; open the Markdown files in an editor, or search them with tools such as grep.

mailmd stores your login details outside the archive. It does not encrypt them, but only your computer user can read them. Keep your computer account secure and consider this when choosing where to store the archive.

Check the copy before relying on it #

Open some older and newer messages in the archive and check that they include any important attachments. Confirm that the folders you care about, such as Inbox, Sent, Archive, and custom folders, appear in the copy. For an additional check, use mailmd’s --keep-raw option to retain original .eml files.

mailmd creates a local archive; it does not import messages back into iCloud Mail or free iCloud storage. Keep the server originals until you have checked the copy. On a Mac, Apple Mail also offers mailbox export to an .mbox package through Mailbox → Export Mailbox; Apple documents that export procedure.

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