How to remove all messages from exim mail queue from a certain user/email

Use this line to delete all messages:

exim -bp | grep [email protected] | sed -r 's/(.{10})(.{16}).*/\2/' | xargs exim -Mrm

It does the following:

exim -bp

Lists the exim mail queue

grep [email protected]

Selects only the lines with a certain mail address

sed -r 's/(.{10})(.{16}).*/\2/'

Selects the ID of the e-mail

xargs exim -Mrm

Deletes the message from the queue

I'm sure it can be optimized, please tell if so and how!


Delete all messages that are from [email protected]. You can add -v to the exim command in order to get more verbose output.

exiqgrep -i -f [email protected] | exim -Mrm

You can do it a slightly different way where you generate a bounce message for each item. This emphasizes to the end user how much harm their compromised mailbox has been causing:

exiqgrep -i -f [email protected] | exim -Mg

The other way to clear exim queue is by print the third fields which in this case will be the email email address. Any result that matches the grep email address will be deleted by exim -Mrm command.

exim -bp | grep [email protected] | awk {'print $3'} | xargs exim -Mrm

In case if you would like to clear the frozen email, you can replace [email protected] with 'frozen'

Tags:

Bash

Spam

Exim