How to clear exim mail queue? Print

  • 0

To clear the Exim mail queue on a cPanel server, you can use the following command-line methods. This is useful if you want to remove stuck, spam, or old emails from the queue.

⚠️ Warning

Be cautious when clearing the queue, especially on a production server. This will permanently delete all queued emails.


✅ 1. View the Queue (Optional, for review)

bash
exim -bp

This shows all queued emails with their message IDs.


 2. Clear the Entire Exim Queue

exim -bp | exiqgrep -i | xargs exim -Mrm
  • exim -bp – lists the queue

  • exiqgrep -i – extracts message IDs

  • exim -Mrm – removes each message


Alternative: Use exiqgrep for filtering

❌ Delete all frozen messages (common with spam):

exiqgrep -z -i | xargs exim -Mrm
  • -z filters frozen messages.

❌ Delete emails older than 7 days:

exiqgrep -o 604800 -i | xargs exim -Mrm
  • 604800 seconds = 7 days


 3. Clear Exim Queue Using WHM (if preferred via UI)

  1. Log in to WHM.

  2. Navigate to Mail Queue Manager (search in the top-left).

  3. Use filters to select emails.

  4. Select messages > Click Delete or Delete All.


 Tips

  • Always check the queue with exim -bp before deleting.

  • You can automate queue cleanup via cron if spam builds up regularly.

 

Advance Scenario

✅ 1. Delete Emails from a Specific Sender

 First, preview messages from a sender:

exiqgrep -f sender@example.com

❌ Then, delete them:

exiqgrep -f sender@example.com -i | xargs exim -Mrm
  • Replace sender@example.com with the actual email address.


✅ 2. Delete Emails Sent by PHP Scripts (e.g., malware or spam)

PHP scripts often send mail with the sender like:

sql
 
<> or nobody@hostname or user@server.hostname

???? Find such emails (run this first to verify):

exiqgrep -f '<>' # Null senders, often PHP scripts

Or check:

exiqgrep -f nobody@yourhostname -i

❌ Delete those:

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

Or:

exiqgrep -f nobody@yourhostname -i | xargs exim -Mrm

✅ 3. Find Emails by Sending Script or Path

This is useful if a particular PHP script is sending spam.

 Find messages sent via PHP (lists the sending paths):

grep -H "cwd=" /var/log/exim_mainlog | grep /home | awk '{print $3,$11}' | sort | uniq -c | sort -n

This gives output like:

ini
cwd=/home/username/public_html/spam-script.php

Then filter queue entries from that script.


✅ 4. Delete All Emails from a Specific Script’s User

If you know the cPanel user, run:

exiqgrep -f user@hostname -i | xargs exim -Mrm

Or delete all mail from scripts under a specific user’s directory:

grep "cwd=/home/username" /var/log/exim_mainlog | awk '{print $3}' | cut -d'=' -f2 | sort | uniq

Then find message IDs with:

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

 Summary

Task Command
Delete from email exiqgrep -f sender@example.com -i | xargs exim -Mrm
Delete null sender exiqgrep -f '<>' -i | xargs exim -Mrm
Delete from PHP script Use grep cwd= /var/log/exim_mainlog and clean accordingly
Delete from user exiqgrep -f user@hostname -i | xargs exim -Mrm

Was this answer helpful?

« Back