Delete Spam from Exim Queue

Spam is a major cause of headache for many people in the world.  Especially server administrators.

Here is a tip to clean up your exim mail queue if its getting to large and full of spam.

Please keep in mind that some legitimate emails may get deleted by this method.  Please use it carefully.  I had more than 2000 emails in my queue, and it was reduced to about 50 after running a few of these.

First, run

grep -R -l [SPAM] /var/spool/exim/msglog/*|cut -b26-|xargs exim -Mrm

The highlighted word will be used in a grep search and replace and all messages matching that will be deleted.  If you also want to remove frozen messages from your queue, run the following

grep -R -l ‘*** Frozen’ /var/spool/exim/msglog/*|cut -b26-|xargs exim -Mrm

You can perform one more that will also clean your exim queue some more

grep -R -l ‘The recipient cannot be verified’ /var/spool/exim/msglog/*|cut -b26-|xargs exim -Mrm

Second tip – if you are using CPanel, set up your mails to default to :fail: rather than :blackhole:


Leave a Reply