Category Archives: Postfix

postfix-delete.pl scipt

#!/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,”|/usr/sbin/postsuper -d -“) || die “couldn’t open postsuper” ;

foreach (keys %Q) {
print POSTSUPER “$_n”;
};
close(POSTSUPER);

How to troubleshoot spamming activities on postfix mail server.

1. To see the mail queue:

mailq

2. To flush the mail queue:

postfix flush

or

postfix -f

3. To remove all mails from the queue:

postsuper -d ALL

4. To remove all mails in the deferred queue:

postsuper -d ALL deferred

5. To delete all queued messages from or to the domain called webserverpage.com:

./postfix-delete.pl webserverpage.com

Note: You may download the script on the link below.

http://blog.webserverpage.com/?p=541

6. To delete all queued messages that contain the word “virus” in the email.

./postfix-delete.pl virus

7. To know the number of messages sitting in the deferred queue:

find /var/spool/postfix/deferred -type f | wc -l

8. Sort user email accounts with corresponding number(s) of email.

mailq|grep ^[A-F0-9]|cut -c 42-80|sort |uniq -c|sort -n|tail