All help articles

Mail cleanup rules

A cleanup rule acts on mail older than an age you choose, every hour. For example: empty Trash after 30 days, delete Junk after a week, or move the Inbox's mail older than two years to Archive.

What a rule says

PartChoices
Mail inEvery folder, or one of Inbox, Sent, Drafts, Archive, Junk and Trash. Folders people made themselves count under Every folder only.
Older thanA number of hours, days, weeks, months or years, counted from when the message arrived (or was sent or saved).
ThenMark it read, Move it to Archive, Move it to Trash, or Delete it.
ForEvery mailbox of the tenant, every mailbox on one of its domains, or one mailbox.
Leave starred mail aloneOn by default: starred (flagged) messages are never touched.
Only mail already readOff by default: when on, unread mail is left.

A rule never moves mail to the folder it is already in (Trash to Trash). A mailbox with no Archive or Trash folder is skipped by rules that move mail there. Delete it takes the message out of the rule's folders, and deletes it for good once it is in no other folder; it cannot be undone.

Who sets rules

The magnifying glass beside a rule counts what it would change if it ran now, without changing anything. Last run shows when it ran and how many messages it changed. Pause stops a rule without removing it.

A rule that deletes mail skips every mailbox on legal hold, its own or its whole tenant's (see Compliance archiving), until the hold is lifted. Rules that only mark mail read or move it still run. Mail the compliance archive keeps is not affected by any rule.

How much runs at once

Each rule changes up to 50,000 messages an hour, oldest first; the rest follow in the next hours. Mail apps see the changes at once, as if someone had moved or deleted the messages (IMAP, JMAP and webmail).

From the API

GET and POST /v1/tenants/{tenantId}/cleanup-rules, PATCH and DELETE /v1/tenants/{tenantId}/cleanup-rules/{ruleId}, and GET .../cleanup-rules/{ruleId}/preview. A rule is {"folder": "trash", "olderThan": 30, "unit": "days", "action": "delete"}, with optional domain or accountId, name, keepStarred, onlyRead and enabled. Tenant API keys limited to some domains cannot use these. See api/openapi.yaml (Mail cleanup).