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)
This shows all queued emails with their message IDs.
2. Clear the Entire Exim Queue
-
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):
-
-z
filters frozen messages.
❌ Delete emails older than 7 days:
-
604800
seconds = 7 days
3. Clear Exim Queue Using WHM (if preferred via UI)
-
Log in to WHM.
-
Navigate to Mail Queue Manager (search in the top-left).
-
Use filters to select emails.
-
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:
❌ Then, delete them:
-
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:
???? Find such emails (run this first to verify):
Or check:
❌ Delete those:
Or:
✅ 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):
This gives output like:
Then filter queue entries from that script.
✅ 4. Delete All Emails from a Specific Script’s User
If you know the cPanel user, run:
Or delete all mail from scripts under a specific user’s directory:
Then find message IDs with:
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 |