To delete pending emails in the Exim queue, follow these steps:
Step 1: Check Total Email Count in the Queue
exim -bpc
This command shows how many messages are currently in the queue.
Step 2: Filter Emails Based on Requirements
Filter All Frozen Emails:
exim -bp | exiqgrep -z
Filter All Unfrozen Emails:
exim -bp | exiqgrep -x
Filter by Sender:
exim -bp | exiqgrep -f [email protected]
Step 3: Review the Emails Before Deleting
The output will display:
-
Time in queue
-
Message size
-
Exim message ID
-
Sender email
-
Whether the message is frozen
-
Recipient email
Step 4: Delete Selected Emails
Warning: These actions are irreversible. Deleted emails cannot be recovered.
Delete All Frozen Emails:
exiqgrep -z -i | xargs -r exim -Mrm
Delete All Unfrozen Emails:
exiqgrep -x -i | xargs -r exim -Mrm
Delete All Emails by a Specific Sender:
exiqgrep -f [email protected] -i | xargs -r exim -Mrm
Make sure to use the correct sender email and double-check the filtered list before running deletion commands.
Forcefully Remove All Emails from the Exim Queue (Including Locked or Stuck Messages)
If you want to remove all emails in the queue regardless of status, use the following:
exim -bp | awk '{print $3}' | xargs -r exim -Mrm
Explanation:
-
exim -bp: Lists all queued messages. -
awk '{print $3}': Extracts message IDs. -
xargs -r exim -Mrm: Removes all identified messages.
If Messages Are Locked and Cannot Be Deleted Normally
Stop Exim and manually clear the spool directories:
service exim stop
rm -rf /var/spool/exim/input/*
rm -rf /var/spool/exim/msglog/*
service exim start
Clear Exim Retry Database (Optional)
Remove retry data for stuck delivery attempts:
rm -f /var/spool/exim/db/retry
Alternative Method: Remove Emails via WHM Interface
-
Log in to WHM.
-
Go to Email > Mail Queue Manager.
-
Use the "Delete all messages in queue" option or manually remove selected entries.
Note: Always verify messages before deletion to avoid removing legitimate emails.
