Small Script to delete 1 or more emails from postfix queue


#!/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,"|cat") || die "couldn't open postsuper" ;
open(POSTSUPER,"|postsuper -d -") || die "couldn't open postsuper" ;

foreach (keys %Q) {
print POSTSUPER "$_\n";
};
close(POSTSUPER);

I have this stored out of the system path in a file called “delfromq

Some examples

./delfromq "domainname.com"
./delfromq "MAILER-DAEMON"
./delfromq "full-email-address@domainname.com"

Sorry I can’t give credit for this script as I have had it for so long I forgot where I got it from.

Be the first to comment

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.