Postfix commands for managing mailserver queue etc.
Do You know any handy postfix mailserver commands or scripts for managing it? Please kindly share these. Im pasting ones that can be handy
Watch postfix log:
tail -f -n100 /var/log/maillog
stop postfix:
Code:
service postfix stop
stop postfix
See the sizes of the Postfix folders
Code:
du -h /var/spool/postfix --max-depth=1
Postfix mail queue sumary:
or
Code:
sendmail -bp
or
postqueue -p
see some message details
postcat -qv 3BC371BAD02D6
try to deliver queued emails:
remove deferred mails:
Code:
postsuper -d ALL deferred;postsuper -d ALL defer
remove all mails from postfix queue:
Thanks to following perl script (postfix-delete.pl) delete mails from some domain.tld or contianing some word
Code:
#!/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);
delete mails containing domain.com
Code:
./postfix-delete.pl spamdomain.com
delete mails containing lottery
Code:
./postfix-delete.pl lottery
How to identiffy source of spam on Postfix mailserver: http://unix.stackexchange.com/a/121548