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

Want to support HowtoForge? Become a subscriber!
 
Submitted by falko (Contact Author) (Forums) on Tue, 2008-01-15 12:04. :: Postfix

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

Version 1.0
Author: Falko Timme <ft [at] falkotimme [dot] com>
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 falko@example.com or are sent to falko@example.com (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.


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by radim_h (registered user) on Fri, 2013-08-30 15:58.

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 ~/^username@domain.tld$/ { print $1 }' | tr -d '*!' | postsuper -d -or for </code>

 

Submitted by Anonymous (not registered) on Mon, 2014-12-15 21:07.
this one works for me on debian ... THANX
Submitted by Anonymous (not registered) on Fri, 2011-03-11 10:41.
You should probably use tail -n +2 instead of tail -2 which is deprecated and does not work everywhere.
Submitted by Anonymous (not registered) on Sat, 2012-01-14 06:31.

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 -

Submitted by Edo (not registered) on Fri, 2013-04-05 14:00.

For me works this

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

Submitted by Dan Purcell (not registered) on Tue, 2013-01-15 00:26.

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 -

Submitted by Anonymous (not registered) on Thu, 2014-08-28 05:55.
This was the only one that worked for me on RHEL
Submitted by Anonymous (not registered) on Tue, 2014-05-06 22:38.
Works on wheezy
Submitted by suther (registered user) on Fri, 2013-06-14 08:21.

+1 for your Comment.

This Command works for me too on Debian Squeeze.

Submitted by Anonymous (not registered) on Wed, 2014-05-28 10:48.

Why not:

 

mailq|fgrep someone@example.com|sed 's/\*.*//'|postsuper -d -

Submitted by Bryand (not registered) on Mon, 2014-09-15 17:31.

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


mailq|fgrep monitoringeal@grupoasd.com.co|sed 's/\*.*//'|sudo /opt/zimbra/postfix/sbin/postsuper -d -

this command works for me.