PDA

View Full Version : Postfix commands for managing mailserver queue etc.



Fli
09-02-2014, 11:24 AM
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:

service postfix stop
stop postfix

See the sizes of the Postfix folders

du -h /var/spool/postfix --max-depth=1

Postfix mail queue sumary:

mailq
or

sendmail -bp
or
postqueue -p

see some message details
postcat -qv 3BC371BAD02D6

try to deliver queued emails:

postfix -f

remove deferred mails:

postsuper -d ALL deferred;postsuper -d ALL defer

remove all mails from postfix queue:

postsuper -d ALL

Thanks to following perl script (postfix-delete.pl) delete mails from some domain.tld or contianing some word

#!/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

./postfix-delete.pl spamdomain.com

delete mails containing lottery

./postfix-delete.pl lottery

How to identiffy source of spam on Postfix mailserver: http://unix.stackexchange.com/a/121548