Exim is a free and versatile mail transfer agent (MTA) that has been ported to most Unix-like systems and is currently the default for a few Linux distributions, most popular being the Debian Linux distribution.
Checking Exim’s mail queue
First let’s see if there are any specific messages we want to delete, type in the following command:
# exim -bp
This command lists all the messages in the queue with their respective message id’s, a message returned by this command looks like this:
18h 2.1K 1dMX7a-0001rT-I2 <> *** frozen ***
root@somehost.com
The command to delete a message in Exim is:
# exim -Mrm <message-id>
So, if we want to delete the message in the example above we type in:
# exim -Mrm 1dMX7a-0001rT-I2
Cleaning Exim’s mail queue
Let’s say you have a lot of messages in your mail queue that were generated by a spam script and you want to clear your queue entirely without sending any messages, this can be done with:
# exim -bp | exiqgrep -i | xargs exim -Mrm
As we’ve seen above, the first command (exim -bp) lists all the messages we have in the mail queue, the second command (exiqgrep -i) grabs only the message id’s from the first command and the third command (xargs exim -Mrm) passes the message id’s returned from the second command to the command (exim -Mrm) that is used to delete messages from the queue.
Sometimes you may have mail in the queue that is legitimate that the mail server couldn’t send because of various reasons and you may want to force the mail server to send this mail once the problem is resolved, this is done by using the following command:
# exim -qff
This will force Exim to send every message in the mail queue regardless of whether it is frozen or not. That’s it, you have now successfully cleaned your mail queue.
===========================================================================