bschelst/ January 2, 2017/ Linux/ 0 comments

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 this Post

Leave a Comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>
*
*

4 + one =