Drop All Mail in Exim
Luke Hebert
- 2 minutes read - 271 wordsSometimes the Exim mail queue fills up with messages you no longer want: a storm of bounces, a misconfigured relay spitting out duplicates, or a test run that went sideways. Rather than removing messages one by one with exim -Mrm <id>, you can clear the entire queue in a single pass.
The One-Liner
exim -bp | awk '/^ *[0-9]+[mhd]/{print "exim -Mrm " $3}' | bashHow It Works
exim -bplists the current mail queue. Each active message line begins with an age indicator like2d,5h, or30m.awk '/^ *[0-9]+[mhd]/{print "exim -Mrm " $3}'matches only those active-message lines (the age pattern) and prints a ready-to-runexim -Mrmcommand using the message ID in field 3.bashexecutes each generated command, removing every message from the queue.
A Safer Dry Run
Before you pipe into bash, preview what will be removed:
exim -bp | awk '/^ *[0-9]+[mhd]/{print "exim -Mrm " $3}'This prints the list of exim -Mrm commands without executing them. Confirm the IDs look right, then add | bash to actually clear the queue.
This removes every message in the queue, including legitimate mail that is simply delayed. Make sure you understand what is in the queue before running the command. If you only want to drop messages older than a certain age, filter the awk pattern accordingly (for example, match only d-suffixed ages to target messages older than one day).
Verifying the Queue Is Empty
After the flush, confirm the queue is clear:
exim -bpYou should see No messages in queue (or an equivalent empty listing) if everything was removed successfully.