Postfix queue administration

Although I’ve used many MTA’s before, I’m new to postfix so here’s a few handy commands to note:

List the mail queue:
postqueue -p
or
mailq

Delete a single message:
postsuper -d 4C63F2300BA

Flush the queue (attempt to deliver all queued mail)
postfix flush
or
postfix -f

To remove all mail from the queue:
postsuper -d ALL

To remove all mail in the deferred queue:
postsuper -d ALL deferred

A handy script to delete all mail in the queue which matches a regex:
#!/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);

Usage:
./postfix-delete.pl fackspamdomain.com
or
./postfix-delete.pl xyz

Thanks to cyberciti for this one

You can leave a response, or trackback from your own site.

Leave a Reply