Deleting mails in exim
Sometimes it is necessary to clean out the mail queue on your server. Emails being stuck cause the complete mail flow to stop or to dramatically slow down. Customers will complain and the server performance goes down hill. Time to look at the mail queue a little closer. To flush the exim queue from the command line do the following:
1. Login to your dedicated server via ssh and switch to the root user.
2. At the command line prompt type: exim -qff
That is it. If you need to turn on debugging for a more detailed picture when flushing the mail queue use the following command:
At the command line type: exim -qff -d9
If you have a cPanel server you can also clean the mail queue from the WHM control panel. Login to your WHM control panel and scroll down to “Email”. Click on “Manage Mail Queue” and you will see the current messages in your mail queue. You look at messages, delete messages or try to deliver messages. Very important is the part that shows you how long messages are already sitting in your mail queue. In most cases anything sitting there for more than 30 hours cannot be delivered - period. We usually delete anything older than 24 hours from our servers. In WHM you can choose to delete single messages or all messages at once. Make sure that you check mail queue every once in a while and do a clean up. Only a clean system will run smoothly.
One can also use the following bash script to delete certain messages from the queue
# remove msges from exim queue
if test -z mailq ; then
echo "No Messages in Exim Queue -exit"
exit 0
fi
if [ "$1" = "" ] || [ "$2" = "" ]; then
echo "Usage remexim email_address [-p postpone] [ -r remove]"
exit 0
fi
h=$(grep -l $1 /var/spool/exim/msglog/*|cut -b24-)
if [ ! $h = "" ]; then
a=("/var/spool/exim/input/"$h"-H")
c=$(grep 'Subject:' $a)
if [ "$2" = "-p" ]; then
#cat "/var/spool/exim/input/"$h"-D"
cat "/var/spool/exim/input/"$h"-D"
exit 0
fi
if [ "$2" = "-r" ]; then
echo "Remove Msg With " $c " ID "$h" y/N"
read a
if [ $a = "y" ]; then
exim -Mrm $h
echo "removed"
else
echo "Exit"
fi
fi
else
echo "No such address"
fi


May 12th, 2006 at 2:53 am e
use the following command. Its clean, simple and easy. It does the same as the above code does.
grep -R -l ‘mymail@mymail.blah’ /var/spool/exim/msglog/*|cut -b26-|xargs exim -Mrm