Managing-The-Postfix-Queues: Difference between revisions
m (Protected "Ajcody-Managing-The-Postfix-Queues" ([Edit=Allow only administrators] (indefinite) [Move=Allow only administrators] (indefinite))) |
No edit summary |
||
Line 1: | Line 1: | ||
{{BC| | {{BC|Certified}} | ||
__FORCETOC__ | __FORCETOC__ | ||
<div class="col-md-12 ibox-content"> | <div class="col-md-12 ibox-content"> | ||
=Managing The Postfix Queues= | =Managing The Postfix Queues= | ||
{{KB|{{ | {{KB|{{ZC}}|{{ZCS 8.5}}|{{ZCS 8.0}}|{{ZCS 7.0}}|}} | ||
{{WIP}} | {{WIP}} | ||
==Postfix, Amavis, Clamav Spool Directory Paths And Names== | ==Postfix, Amavis, Clamav Spool Directory Paths And Names== | ||
Line 459: | Line 459: | ||
{{NeedSME|SME1|SME2|Copyeditor}} | {{NeedSME|SME1|SME2|Copyeditor}} | ||
[[Category: Author:Ajcody]] | [[Category: Author:Ajcody]] | ||
Revision as of 13:37, 22 June 2016
Managing The Postfix Queues
Postfix, Amavis, Clamav Spool Directory Paths And Names
ls /opt/zimbra/data amavisd clamav dspam postfix
ls /opt/zimbra/data/postfix/spool/ active bounce corrupt defer deferred flush hold incoming maildrop pid private public saved trace
Stop And Starting Postfix And Mta
To only stop and start postfix [as the zombra user] :
postfix stop postfix start
To stop and start postfix, amavis, and clam [as the zimbra user] :
zmmtactl stop zmmtactl start
To See The Postfix Queues
As zimbra using sudo - show a summary of queue count - ~/libexec/zmqstat:
[zimbra@mail37 ~]$ sudo ~/libexec/zmqstat hold=0 corrupt=0 deferred=0 active=0 incoming=0
As zimbra - /opt/zimbra/postfix/sbin/postqueue -p
[zimbra@mail37 ~]$ /opt/zimbra/postfix/sbin/postqueue -p -Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient------- EC753D0D00* 328 Thu Apr 5 14:34:09 sender@sourcedomainname.local recipient@destinationdomainname.local -- 0 Kbytes in 1 Request.
As zimbra - mailq
[zimbra@mail37 ~]$ mailq Mail queue is empty
Qshape - Print Postfix queue domain and age distribution
/opt/zimbra/bin/qshape
References:
Example output:
$ qshape -s hold | head T 5 10 20 40 80 160 320 640 1280 1280+ TOTAL 486 0 0 1 0 0 2 4 20 40 419 yahoo.com 14 0 0 1 0 0 0 0 1 0 12 extremepricecuts.net 13 0 0 0 0 0 0 0 2 0 11 ms35.hinet.net 12 0 0 0 0 0 0 0 0 1 11 winnersdaily.net 12 0 0 0 0 0 0 0 2 0 10 hotmail.com 11 0 0 0 0 0 0 0 0 1 10 worldnet.fr 6 0 0 0 0 0 0 0 0 0 6 ms41.hinet.net 6 0 0 0 0 0 0 0 0 0 6 osn.de 5 0 0 0 0 0 1 0 0 0 4
To View A Message In The Queue
Get the message id and use post cat:
/opt/zimbra/postfix/sbin/postcat -q EC753D0D00
or with more information, include the -v option:
/opt/zimbra/postfix/sbin/postcat -qv EC753D0D00
To Flush Postfix Queue
/opt/zimbra/postfix/sbin/postqueue -f
To Requeue Messages In Postfix
/opt/zimbra/postfix/sbin/postsuper -r ALL
More explanation from the postsuper man page:
-r queue_id Requeue the message with the named queue ID from the named mail queue(s) (default: hold, incoming, active and deferred). To requeue multiple mes- sages, specify multiple -r command-line options. Alternatively, if a queue_id of - is specified, the program reads queue IDs from standard input. Specify "-r ALL" to requeue all messages. As a safety measure, the word ALL must be specified in upper case. A requeued message is moved to the maildrop queue, from where it is copied by the pickup(8) and cleanup(8) daemons to a new queue file. In many respects its handling differs from that of a new local submission. o The message is not subjected to the smtpd_milters or non_smtpd_milters settings. When mail has passed through an external content filter, this would produce incorrect results with Milter applications that depend on original SMTP connection state informa- tion. o The message is subjected again to mail address rewriting and substitution. This is useful when rewriting rules or virtual map- pings have changed. The address rewriting context (local or remote) is the same as when the message was received. o The message is subjected to the same con- tent_filter settings (if any) as used for new local mail submissions. This is useful when content_filter settings have changed. Warning: Postfix queue IDs are reused. There is a very small possibility that postsuper(1) requeues the wrong message file when it is executed while the Postfix mail system is running, but no harm should be done. This feature is available in Postfix 1.1 and later.
To Put Messages On Hold
If there’s ‘*’ character next to queue ID , EC753D0D00* , it means that this message is in the active queue e.g. attempts to deliver the messages are made.
If there’s ‘!’ character next to queue ID , EC753D0D00! , it means that this message is put “on hold”.
To put a message on hold:
~# /opt/zimbra/postfix/sbin/postsuper -h EC753D0D00
To put on hold messages from user@domain.com:
~# /opt/zimbra/postfix/sbin/postqueue -p | awk ‘BEGIN { RS = “” } { if ($7 == “user@domain.com” ) print $1 }’ | tr -d ‘!*’ | postsuper -h -
To put all messages on hold:
~# /opt/zimbra/postfix/sbin/postsuper -h ALL postsuper: Placed on hold: 6 messages
To Delete Messages From Queue
Cautionary Note
- Warning, deleting messages from the queue can have a negative consequence of your users. You might need to account for the action and/or confirm your deletion was appropriate. Please try to save the postqueue -p information from the various messages prior to deleting them. This will at least you give you he information to later justify your actions on why you delete msg#.
Relevant Sections Of Postsuper Man Page
By default, postsuper(1) performs the operations requested with the -s and -p command-line options on all Postfix queue directories - this includes the incoming, active and deferred directories with mail files and the bounce, defer, trace and flush directories with log files. -d queue_id Delete one message with the named queue ID from the named mail queue(s) (default: hold, incoming, active and deferred). If a queue_id of - is specified, the program reads queue IDs from standard input. For example, to delete all mail with exactly one recipient user@example.com: mailq | tail +2 | grep -v '^ *(' | awk 'BEGIN { RS = "" } # $7=sender, $8=recipient1, $9=recipient2 { if ($8 == "user@example.com" && $9 == "") print $1 } ' | tr -d '*!' | postsuper -d - Specify "-d ALL" to remove all messages; for example, specify "-d ALL deferred" to delete all mail in the deferred queue. As a safety measure, the word ALL must be specified in upper case. Warning: Postfix queue IDs are reused. There is a very small possibility that postsuper deletes the wrong message file when it is executed while the Postfix mail system is delivering mail. The scenario is as follows: 1) The Postfix queue manager deletes the message that postsuper(1) is asked to delete, because Postfix is finished with the message (it is delivered, or it is returned to the sender). 2) New mail arrives, and the new message is given the same queue ID as the message that postsuper(1) is supposed to delete. The probability for reusing a deleted queue ID is about 1 in 2**15 (the number of different microsecond values that the system clock can distinguish within a second). 3) postsuper(1) deletes the new message, instead of the old message that it should have deleted. -h queue_id Put mail "on hold" so that no attempt is made to deliver it. Move one message with the named queue ID from the named mail queue(s) (default: incoming, active and deferred) to the hold queue. If a queue_id of - is specified, the program reads queue IDs from standard input. Specify "-h ALL" to hold all messages; for example, specify "-h ALL deferred" to hold all mail in the deferred queue. As a safety measure, the word ALL must be specified in upper case. Note: while mail is "on hold" it will not expire when its time in the queue exceeds the maximal_queue_lifetime or bounce_queue_lifetime setting. It becomes subject to expiration after it is released from "hold". -H queue_id Release mail that was put "on hold". Move one message with the named queue ID from the named mail queue(s) (default: hold) to the deferred queue. If a queue_id of - is specified, the program reads queue IDs from standard input. Note: specify "postsuper -r" to release mail that was kept on hold for a significant fraction of $maximal_queue_lifetime or $bounce_queue_lifetime, or longer. Specify "-H ALL" to release all mail that is "on hold". As a safety measure, the word ALL must be specified in upper case. -p Purge old temporary files that are left over after system or software crashes.
To Delete Single Message From Queue
/opt/zimbra/postfix/sbin/postsuper -d [MSGID From postqueue -p]
To Delete ALL Messages From Queue
/opt/zimbra/postfix/sbin/postsuper -d ALL
Another way to do this:
mailq | awk '{print $1}' | postsuper -d -
To Delete ALL Messages From The Deferred Queue
/opt/zimbra/postfix/sbin/postsuper -d ALL deferred
To Delete ALL Messages From The Hold Queue
/opt/zimbra/postfix/sbin/postsuper -d ALL hold
To Delete Many Messages From Queue
To delete a large number of files one would use:
/opt/zimbra/postfix/sbin/postsuper -d - < filename-with-queue-ids.txt
The filename, filename-with-queue-ids.txt example, would have a listing of id's like:
3E1C6CAFFFE 6B862CC9D76 0BC38CC1BC9 90628CC6F3C E26B9CC3C62 92A35CC943D A84BDBCE15D EA57CB1DF04 0F102CC74CB 386E8CC4DFF 92606CC0BDA 0799FC8149A 024CFCBD0DE 2D30FC47DA0 31D85CC6308 B8B3FC3DEBC AA4C7C913D0 280F5CC8C6C 9F341CC8A26 93CD1B3B0EC 433D0BF3716 A1435CB4C38 2DB04CC911D 56A29CC8819 11881C8268C 5C050A79851 C6739CC4BA5 11D3FCC7D09 8CBC0B20E0A
Delete From Queue By Email Address
Note - Some of the shell scripting below might fail on messages with particular status ("on delivery" or "on hold") because a "*" or a "!" is appended to the ID of the message.
From CLI
Change the [ email@address.com ] variable below first.
To first see what would be deleted. As root:
/opt/zimbra/postfix/sbin/postqueue -p | egrep -v '^ *\(|-Queue ID-' \ | awk 'BEGIN { RS = "" } { if ($7 == "email@domain.com") print $1} ' | tr -d '*!'
If you get error about egrep, you might need to use this syntax:
/opt/zimbra/postfix/sbin/postqueue -p | /bin/egrep -v '*\(|-Queue ID-' \ | awk 'BEGIN { RS = "" } { if ($7 == "email@address.com") print $1} ' | tr -d '*!'
To now delete, just include the postsuper -d at end:
/opt/zimbra/postfix/sbin/postqueue -p | egrep -v '^ *\(|-Queue ID-' \ | awk 'BEGIN { RS = "" } { if ($7 == "email@domain.com") print $1} ' \ | tr -d '*!' | /opt/zimbra/postfix/sbin/postsuper -d -
Older example of what I had; the tail +2 was rhel4 specific
- To first see what would be deleted:
mailq | tail +2 | grep -v '^ *(' | awk 'BEGIN { RS = "" } { if ($8 == "email@address.com" && $9 == "") print $1 } ' | tr -d '*!'
- To now delete, just include the postsuper -d at end:
mailq | tail +2 | grep -v '^ *(' | awk 'BEGIN { RS = "" } { if ($8 == "email@address.com" && $9 == "") print $1 } ' | tr -d '*!' | postsuper -d -
Script To Delete From Queue By Email Address
- Non-Zimbra Script and not QA'd or tested. Path adjusted though for /opt/zimbra/postfix/sbin/*
From http://www.ustrem.org/en/articles/postfix-queue-delete-en/
Save on file system, calling it something like - delete-queue-by-email.sh . Give it execute permission. Run as root. Example usage would be: ./delete-queue-by-email.sh user-name@domain-test.com
#!/usr/bin/perl -w # # pfdel - deletes message containing specified address from # Postfix queue. Matches either sender or recipient address. # # Usage: pfdel <email_address> # use strict; # Change these paths if necessary. my $LISTQ = "/opt/zimbra/postfix/sbin/postqueue -p"; my $POSTSUPER = "/opt/zimbra/postfix/sbin/postsuper"; my $email_addr = ""; my $qid = ""; my $euid = $>; if ( @ARGV != 1 ) { die "Usage: pfdel <email_address>\n"; } else { $email_addr = $ARGV[0]; } if ( $euid != 0 ) { die "You must be root to delete queue files.\n"; } open(QUEUE, "$LISTQ |") || die "Can't get pipe to $LISTQ: $!\n"; my $entry = <QUEUE>; # skip single header line $/ = ""; # Rest of queue entries print on # multiple lines. while ( $entry = <QUEUE> ) { if ( $entry =~ / $email_addr$/m ) { ($qid) = split(/\s+/, $entry, 2); $qid =~ s/[\*\!]//; next unless ($qid); # # Execute postsuper -d with the queue id. # postsuper provides feedback when it deletes # messages. Let its output go through. # if ( system($POSTSUPER, "-d", $qid) != 0 ) { # If postsuper has a problem, bail. die "Error executing $POSTSUPER: error " . "code " . ($?/256) . "\n"; } } } close(QUEUE); if (! $qid ) { die "No messages with the address <$email_addr> " . "found in queue.\n"; } exit 0;
Script To Delete From Queue By Various Variable Targets
- Non-Zimbra Script and not QA'd or tested. Path adjusted though for /opt/zimbra/postfix/sbin/*
From http://jwcub.wordpress.com/2006/01/20/bulk-delete-from-postfix-queue/
Perl script called “delete-from-mailq”:
#!/usr/bin/perl $REGEXP = shift || die “no email-adress given (regexp-style, e.g. bl.*\@yahoo.com)!”; @data = qx; for (@data) { if (/^(\w+)(\*|\!)?\s/) { $queue_id = $1; } if($queue_id) { if (/$REGEXP/i) { $Q{$queue_id} = 1; $queue_id = “”; } } } open(POSTSUPER,”|/opt/zimbra/postfix/sbin/postsuper -d -”) || die “couldn’t open postsuper” ; foreach (keys %Q) { print POSTSUPER “$_\n”; }; close(POSTSUPER);
Save the above script to a file say “delete-queue.pl” in your home directory, and make it excutable:
chmod 755 delete-queue
Usage - Run as root :
- Delete all queued messages from or to the domain “iamspammer.com”
./delete-queue iamspammer.com
- Delete all queued messages to specific address “bogususer@mydomain.com”
./delete-queue bogususer@mydomain.com
- Delete all queued messages that begin with the word “bush” in the e-mail address:
./delete-queue bush*\@whateverdomain.com
- Delete all queued messages that contain the word “biz” in the e-mail address:
./delete-queue biz