postimg
Mar 2010 05

Clearing Out Postfix Deferred Mail Queue1

Posted In Perl By Tony Virelli

I had a bit of a situation with my Postfix Mail Queue. Mail stopped sending and the queue built up. When I did a mailq I found a lot of double-bounce@domain.com emails in my queue. I knew it would take forever for those to clear and get the good mail flowing again.

So after doing some searching on Google I found this site:
http://www.cyberciti.biz/tips/howto-postfix-flush-mail-queue.html

It has some of the common Postfix commands, but what interested me was the Perl script to delete mailqs that matched regular expressions.

postfix-delete.pl script

The following script deletes all mail from the mailq which matches the regular expression specified as the first argument.

(Credit: Vivek Gite of cyberciti.biz. His credit: Credit: ??? – I found it on old good newsgroup)

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

For example, delete all queued messages from or to the domain called double-bounce@domain.com, enter:

./postfix-delete.pl double-bounce@domain.com

Delete all queued messages that contain the word “xyz” in the e-mail address:

./postfix-delete.pl xyz

For more information about this script make sure and checkout http://www.cyberciti.biz/tips/howto-postfix-flush-mail-queue.html

1 comment

  1. John says:

    I love the obvious Mexi mobile in the picture. It’s the red blazer, when you see it you will know.

Leave a comment

Get Adobe Flash playerPlugin by wpburn.com wordpress themes