Email backup

How to Back Up Microsoft 365 Email

Updated 3 min read

Microsoft 365 email for work or school is stored in Exchange Online, Microsoft’s hosted email service. A backup is a separate copy kept so you can recover messages after deletion or loss. Outlook keeping your mailbox in sync and Microsoft protecting its service against failures do not, by themselves, give you a simple local archive of older mail.

For a readable copy on your own computer, mailmd is the recommended tool: it copies messages into Markdown files, one per email, without changing the mailbox. For administrator-managed recovery inside Microsoft 365, use Microsoft 365 Backup instead. The right choice depends on whether you need a local archive or a service designed to restore mailbox content.

Create a local email archive with mailmd #

mailmd is a free, open-source command-line tool. A command-line tool runs through text commands rather than a graphical interface. mailmd connects to Microsoft 365 through Microsoft Graph, an API (a way for software to access Microsoft services). Setup requires registering an OAuth app in Microsoft Entra, Microsoft’s identity and access service. This app lets mailmd request access to your mailbox.

Install mailmd, then connect your account and sync your messages:

curl -fsSL https://raw.githubusercontent.com/vincentsch/mailmd/main/install.sh | sh
mailmd connect outlook --client-id <id>
mailmd sync

Use the Microsoft Entra app’s client ID, its identifying code, in place of <id>. The sign-in request asks for read access, and you enter your password yourself. mailmd opens mailbox folders in read-only mode; it does not mark messages as read, move or delete mail, or send messages. The archive is saved under ~/mail/<account>.

Each message becomes a Markdown file. At the top, a metadata section called frontmatter lists email headers such as sender and date. HTML messages become readable Markdown. Attachments are saved beside their messages, and mail folders and years become directories. To keep the original email file too, run mailmd sync --keep-raw. The index.jsonl file lists messages for scripts.

Run mailmd sync again to add new mail and update which messages are marked as read or starred. If mail is later deleted from Microsoft 365, its archived file remains and is marked as deleted on the server. Spam and trash are excluded unless requested; Gmail’s All Mail folder is included when syncing through IMAP.

To keep the archive up to date, schedule mailmd sync --quiet to run automatically on your computer. Keep the archive in a separate backup of your computer as well: a copy stored only on one device is vulnerable if that device fails. mailmd does not provide a search engine, but you can search the files with an editor or tools such as rg or grep.

Login details are stored outside the archive and are readable by your user, but are not encrypted. mailmd has no telemetry or mailmd server. It is an archive tool, not a mail client, and it does not restore messages into Microsoft 365 or convert them to PST or PDF. For setup instructions, see the mailmd project.

Use Microsoft 365 Backup for mailbox restoration #

If administrators need to restore mailbox items inside Microsoft 365, they can configure Microsoft 365 Backup. The paid, administrator-managed service requires billing setup and a backup policy; end users cannot enable it themselves. Microsoft’s current policies let administrators keep backups for three months, six months, one year, or two years. Each policy must include the mailboxes to back up. See Microsoft’s setup instructions and policy options.

Restoration brings back deleted or modified items from a chosen recovery point, a saved point in time. It does not recreate every detail of the mailbox as it looked at that time: unchanged messages are not duplicated, and newer messages are not removed. Review Microsoft’s Exchange restore limits before relying on the service for a particular recovery scenario.

Microsoft also retains deleted items for recovery under configured conditions, but that is a limited safety net rather than a historical archive. Its Exchange deletion guidance describes those retention rules. An Outlook OST file is a synchronized offline copy that Outlook can recreate from the server, so copying it does not provide the same protection as an independent archive (Microsoft’s OST explanation).

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