Back to blog

cPanel disk space management: automating email cleanup with Dovecot queries

1/12/2026 · 2 min · cPanel

Share

Disk exhaustion from old mail is a frequent hosting issue. It is often caused by silent failure of cleanup automation, not sudden traffic growth.

Operational failure pattern

In this case, maintenance scripts were removed or moved during migrations. Impact:

Immediate remediation was restoring cleanup routines through cron.

Native cPanel cleanup using Dovecot queries

Beyond root-level scripts, Email Disk Usage in cPanel supports custom queries using Dovecot syntax for granular cleanup.

1) Time-based cleanup

savedbefore 30d

Targets messages saved more than 30 days ago.

2) Sender-based cleanup

from "alertas@dominio.com.br"

Useful for high-volume automated senders.

3) Smart Trash/Spam cleanup

Inside Trash, use:

all

To remove all messages in selected folder.

Or:

seen savedbefore 15d

To delete only old read items.

Quick query reference

GoalDovecot query
Messages larger than 10 MBlarger 10M
Old unread messagesunseen savedbefore 60d
Filter by subjectsubject "Backup diário"
Messages before datebefore 01-Jan-2024

Operational best practices

  1. Audit cron jobs after migrations and panel updates.
  2. Train users to use Email Disk Usage for self-service.
  3. Always preview hit count before mass deletion.
  4. Define retention policy per mailbox type.

Advanced SSH option

You can apply the same logic in batch mode with:

This scales maintenance across many mailboxes.

Sustainable email storage management combines server automation and precise Dovecot query filtering in cPanel. This prevents full-disk incidents while preserving important data.

CC BY-NC

This post is licensed under CC BY-NC.

Comments

Join the discussion below.