How To Delete Mails From Or To A Specific Email Address From Your Mail Queue (Postfix)

Version 1.0
Author: Falko Timme
Last edited 01/04/2008

If you get hit by a spam attack that floods your server with hundreds/thousands of emails from the same sender email address or to the same recipient email address, you can clean your mail queue from these emails with one single command before the mail flood takes your server to its knees.

You can check your current mail queue like this:

postqueue -p

To delete all mails from the mail queue that come from [email protected] or are sent to [email protected] (the command is the same regardless of if it's the sender or recipient address), you can use this command:

mailq | tail +2 | awk 'BEGIN { RS = "" } / falko@example\.com$/ { print $1 }' | tr -d '*!' | postsuper -d -

Afterwards check your mail queue again:

postqueue -p

It should now be much shorter.

Share this page:

14 Comment(s)

Add comment

Comments

From: Anonymous at: 2011-03-11 09:41:47

You should probably use tail -n +2 instead of tail -2 which is deprecated and does not work everywhere.

From: Anonymous at: 2012-01-14 05:31:38

Hello, I've the same problem. more than 60000 mails is in the mail queue! and I can't delete it, handy. I use this command and after 1 second it will done without any error but it doesn't work.

 


mailq | tail -n +2 | awk 'BEGIN { RS = "" } / info@mail\.com$/ { print $1 }' | tr -d '*!' | postsuper -d -

From: Dan Purcell at: 2013-01-14 23:26:53

It worked for me when I ran it this way:

postqueue -p | tail -n +2 | awk 'BEGIN { RS = "" } / byrdsnestquilt@bellsouth\.net/ { print $1 }' | tr -d '*!' | postsuper -d -

From: at: 2013-06-14 07:21:58

+1 for your Comment.

This Command works for me too on Debian Squeeze.

From: Anonymous at: 2014-05-28 09:48:43

Why not:

 

mailq|fgrep [email protected]|sed 's/\*.*//'|postsuper -d -

From: Bryand at: 2014-09-15 16:31:01

mailq | tail -n +2 | awk 'BEGIN { RS = "" } / mailbox@asd\.com.mx$/ { print $1 }' | tr -d '*!' | sudo /opt/zimbra/postfix/sbin/postsuper -d -


mailq|fgrep [email protected]|sed 's/\*.*//'|sudo /opt/zimbra/postfix/sbin/postsuper -d -

this command works for me.

From: Anonymous at: 2014-05-06 21:38:32

Works on wheezy

From: Anonymous at: 2014-08-28 04:55:38

This was the only one that worked for me on RHEL

From: Edo at: 2013-04-05 13:00:03

For me works this

mailq | tail -n +2 | awk 'BEGIN { RS = "" } / info@mail\.com$/ { print $1 }' | tr -d '*!' | sudo postsuper -d -

From: at: 2013-08-30 14:58:53

The above commands are not working

For deleting email from some domain, you can use
<code> mailq | awk '$7 ~ /@domain.tld$/ { print $1 }' | tr -d '*!' | postsuper -d -</code>

for deleting email from specified user, use 
<code>mailq | awk '$7 ~/^[email protected]$/ { print $1 }' | tr -d '*!' | postsuper -d -or for </code>

 

From: Anonymous at: 2014-12-15 20:07:50

this one works for me on debian ... THANX

From: Some Guy at: 2015-02-27 19:22:08

postsuper -d <queue id> works much more easily.

get the id from postqueue -p:

8D609414BFF4     9564 Fri Feb 27 10:42:42  [email protected]

(conversation with mail.owlpic.com[64.38.116.11] timed out while receiving the initial server greeting)

So in this case

postsuper -d 8D609414BFF4

 

From: till at: 2015-03-01 18:00:51

If you have just one or two mails, then yes. If you have o clean up a few thousand spam mails, then its more handy to use a script like the one above. 

From: DearWebby at: 2015-04-24 04:31:03

Nice for Postfix, but how do I do that with SENDMAIL?