Postfix commands

# See config
postconf -e
 
# See mail queue
mailq
 
 
# Show deferred
qshape deferred
# Show all
qshape deferred incoming active
 
# Delete deferred
postsuper -d ALL deferred

Delete via regex

Delete all at fackspamdomain.com

./postfix-delete.pl fackspamdomain.com

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

./postfix-delete.pl xyz
#!/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);