Postfix: Clear postfix mail queue

Is your postfix mail queue full of spam? You are not the only one 🙂
In that case it could be interesting to clear your queue, before the spam gets send out.
In order to remove all mail from the postfix queue, execute the following command as superuser:

  #>  postsuper -d ALL

Do you only want to delete mails to or from a domain? In that case you can use a small perl script:

#!/usr/bin/perl  
$REGEXP = shift || die "No email-adress given (regexp-style, e.g. bl.*\@yahoo.com)!";   @data = qx</usr/sbin/postqueue -p>; for (@data) {   if (/^(\w+)(\*|\!)?\s/) {      $queue_id = $1;   }   if($queue_id) {     if (/$REGEXP/i) {       $Q{$queue_id} = 1;       $queue_id = "";     }   } }   open(POSTSUPER,"|postsuper -d -") || die "couldn't open postsuper" ;   foreach (keys %Q) {   print POSTSUPER "$_\n"; }; close(POSTSUPER);

Save it somewhere on the server,make it executable and execute it like this:

.\remote.pl spammer.com
Share your love