Development and databases

Delete old emails safely

Reviewed on 3 min read espacio de correo cron

You can clean up old email without directly handling the mailbox's internal files. First decide which account, folder and period you want to keep; the modification date of a Maildir file is not necessarily the age of the message.

Do a controlled clean-up

In cPanel > Email Disk Usage, select the account and the folder. Review the available queries and keep a recoverable copy before deleting messages.

  1. Test the rule on a test mailbox with messages of known dates.
  2. Confirm whether the condition uses date, size or another criterion. Do not confuse a large-messages rule with an age policy.
  3. Check that the copy lets you recover a message into a temporary folder.
  4. Run the clean-up on the chosen account and folder.
  5. Check webmail, the IMAP client and the quota after the update.

Custom queries do not give a preview of every message they are going to delete. Do not run them on an important mailbox without having tested the criterion and the recovery.

If you need to repeat it automatically

The manual clean-up tool does not schedule a retention policy. To automate it, use a feature supported by the server or an IMAP client that lets you limit and check its scope.

Define the exact account and folder, the date to be used, the exclusions, the frequency and the results log. The first run should list candidates without deleting anything. Then test the whole process and the recovery on a test mailbox before scheduling it.

In IMAP, marking a message as deleted and deleting it permanently are different actions. Check the scope of the permanent purge: some operations may also affect messages already marked by another client.

What to avoid

Do not turn a find -mtime over Maildir into a deletion job or move its files by hand as if they were independent documents. You can break indexes, lose message states or act on a date that does not represent what you want to keep.

If you do not have a tool that lets you verify the criterion and recover what was deleted, carry on with manual clean-up or contact us to review a compatible policy. Stop the job if messages are affected by mistake and recover them from the copy using the supported procedure.

You may also find useful

Something wrong or out of date? Tell us and we will review it.