6

I've spend the last hour trying to figure out how to delete all messages from a certain mail address from the exim mail queue, after the queue was full of spam emails.

Tim Baas
  • 281
  • 2
  • 5
  • 15

3 Answers3

6

Use this line to delete all messages:

exim -bp | grep email@address.com | sed -r 's/(.{10})(.{16}).*/\2/' | xargs exim -Mrm

It does the following:

exim -bp

Lists the exim mail queue

grep email@address.com

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!

Tim Baas
  • 281
  • 2
  • 5
  • 15
  • 1
    Instead of `sed ...` I normaly use `awk '{print $3}'` - prints the third column with the IDs. It's a tiny bit shorter. – vstm Nov 25 '14 at 20:47
  • Alternatively, you can use exiqgrep to get the same effect without the sed or awk. – liamvictor Sep 08 '15 at 11:53
4

Delete all messages that are from sender@example.com. You can add -v to the exim command in order to get more verbose output.

exiqgrep -i -f sender@example.com | 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 sender@example.com | exim -Mg
Todd Lyons
  • 2,006
  • 16
  • 12
  • I found about this right here: http://techinterplay.com/remove-mails-exim-queue-sender.html, problem is my CentOS server doesn't have the `exiqgrep` program.. Thanks for the solution though! – Tim Baas Feb 01 '14 at 23:41
  • The exiqgrep script is a standard part of exim that is included with the tarball. Use 'yum search */exiqgrep' to see if it is provided by any packages on your system that either are not installed or if it is not in your path. Install it if it is available. – Todd Lyons Feb 03 '14 at 13:25
  • Does that work without xargs after the pipe? – Saxtus Feb 19 '19 at 12:35
  • 1
    This doesn't work: "exim: no message ids given after -Mrm option" – ygoe Jun 10 '20 at 20:21
  • 2
    These work for me: `exiqgrep -i -f sender@example.com | xargs exim -Mrm` and `exiqgrep -i -f sender@example.com | xargs exim -Mg` – ThomasEdwin Jun 19 '20 at 07:55
3

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 emai@address.com | awk {'print $3'} | xargs exim -Mrm

In case if you would like to clear the frozen email, you can replace email@address.com with 'frozen'

pellepuns
  • 31
  • 1