Skip to content

Clearing a backed-up Exim queue without dropping legitimate mail

A safe sequence for unclogging an Exim queue on a cPanel server that distinguishes spam, bounces, and legitimate stuck mail before deleting anything.

The instinct when an Exim queue hits 80,000 messages is to flush it. That instinct usually deletes legitimate customer mail mixed in with the spam from the compromise. A safe cleanup separates the queue into three buckets — spam from the abuse, undeliverable bounces, and stuck legitimate mail — and acts on each independently. The whole operation takes longer than exim -bpc | xargs exim -Mrm but you keep your customers’ trust.

What’s happening

When something compromises an account or a script goes haywire, Exim accepts the messages, attempts delivery, and queues whatever defers. The queue grows fast: every message has a -D (data) and a -H (header) file in /var/spool/exim/input/. A 100K queue is a few gigabytes of disk and minutes of exim -bp listing time. Flushing wholesale is fast and unsafe. Triage first.

How to verify

Get the queue size and a breakdown:

exim -bpc
exim -bp | head -50
exim -bp | awk '{print $4}' | grep -v "^$" | sort | uniq -c | sort -rn | head

The last command groups by sender so you can see which user or domain is responsible for the bulk. Cross-check the top sender against the abuse account.

The fix

  1. Identify the abuse source. Use the breakdown above. The compromised account is usually responsible for 70%+ of the queue. Lock it (suspend the cPanel user, change password, kill active sessions) before touching the queue, or you’ll re-fill it.

  2. Delete the abuse traffic by sender. Targeted:

    exiqgrep -i -f "compromised@example.com" | xargs exim -Mrm

    exiqgrep finds messages matching a pattern; -Mrm removes them. Confirm the count first by running without the pipe to -Mrm.

  3. Inspect bounces. Mail with sender <> is bounce traffic. Most should be removed once the abuse is gone:

    exiqgrep -i -f '<>' | xargs exim -Mrm

    Read a handful first to confirm they’re all bounces and not legitimate delivery status notifications.

  4. For the remainder, force a queue run to flush the legitimate stuck mail:

    exim -qff

    -qff retries every frozen message; combined with -q -v for verbosity, you’ll see which destinations are actually accepting now.

  5. For mail stuck on dead domains, freeze and discard those messages specifically — don’t blanket-delete by age. exim -bp with a date filter helps surface the truly abandoned messages.

For environments where a queue spike is an incident and not a footnote, Stack Harbor builds the triage runbook into cPanel/WHM management so the next on-call doesn’t reinvent it.