Linux: Exim Remove All messages From the Mail Queue

How can I remove all the messages from the Exim mail queue from command line? That is a question made by many jr system administrators, webmasters and developers.

Sometimes you need to clean  or remove all the messages on Exim mail queue, you can do it either from a web interface like Web Host Manager if you are using cPanel. Or you can remove all exim messages using the command line on any Linux / Unix operating system.

Exim is a mail transfer agent (aka. MTA), it’s fast, comes with many configuration options, easy to use and works well for all kind of email needs.

On this post I will show you how to remove all emails from your exim server mail queue. This is specially useful when your server is being exploited by spam scripts that cause high load averages on server, making it slower than usual, and causing users to complain about emails not working normally.

Remove All Messages from Exim Mail Queue

First things first. Let’s find out the list of messages in the queue

Command to print list of the messages in the exim mail queue:

exim -bp

If you need to remove a particular message, once you have the ID, you can run this command. Make sure you replace {message-id} with the real ID of the email.

exim -Mrm {message-id}

Remove all messages from the exim queue

Type this command to clean out the exim mail queue. Be aware that this may take some time, from minutes to hours, depending how many emails you have, your load average and how fast are your disks.

exim -bp | awk '/^ *[0-9]+[mhd]/{print "exim -Mrm " $3}' | bash

Anther good alternative to clean the exim mail queue using exim command with exigrep

exim -bp | exiqgrep -i | xargs exim -Mrm

And the last dirty way to remove exim mail queues:

rm /var/spool/exim/input/*

Further readings:

 

About the Author: Martin Keler

Leave a Reply

Your email address will not be published. Required fields are marked *