This perl script will bulk remove emails from the Postfix mail queue based on a keyword, email domain, or email address. The script came from this blog post:
#!/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);
Before running the script:
chmod 755 <scriptName.pl>
Example commands:
./<scriptName.pl> iamspammer.com ./<scriptName.pl> bogususer@mydomain.com ./<scriptName.pl> bush*\@whateverdomain.com ./<scriptName.pl> biz