The old command won’t work anymore on my ubuntu server because of the error: tail: cannot open `+2’ for reading: No such file or directory OLD Command:
`
mailq | tail +2 | grep -v ‘^ (’ | awk ‘BEGIN { RS = "" } { if ($8 == “user@example.com” && $9 == “") print $1 } ’ | tr -d ‘!’ | postsuper -d -
`
NEW Command:
`
mailq | tail -n +2 | grep -v ‘^ (’ | awk ‘BEGIN { RS = "” } { if ($7 == “user@example.com”) print $1 } ’ | tr -d ‘!’ | postsuper -d -
`
Tnx to: i8n1
The above script only work for a specific email adres. Use the following script for bulk remove mail
#!/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);
For example, delete all queued messages from or to the domain called fackspamdomain.com, enter:
./postfix-delete.pl fackspamdomain.com
You can alos use
./postfix-delete.pl fackspam
Or an IP
./postfix-delete.pl 83.160.69.66
Source: http://www.cyberciti.biz/tips/howto-postfix-flush-mail-queue.html