This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
internet:mail:postfix_queue_mgmt [2014/01/09 10:43] gcooper |
internet:mail:postfix_queue_mgmt [2018/11/02 07:11] (current) gcooper |
||
---|---|---|---|
Line 21: | Line 21: | ||
< | < | ||
- | postcat -q <messageID> | head --lines 100 | + | postcat -q <queueID> | head --lines 100 |
</ | </ | ||
Line 58: | Line 58: | ||
==== Purge Mail Queues ==== | ==== Purge Mail Queues ==== | ||
- | Delete | + | To delete all email in the queue from a domain run this command as root: |
+ | |||
+ | postqueue -p | tail -n +2 | awk 'BEGIN { RS = "" | ||
+ | |||
+ | To delete all email in the queue From: a specific email address run this command as root: | ||
+ | |||
+ | postqueue -p | tail -n +2 | awk 'BEGIN { RS = "" | ||
+ | |||
+ | To delete | ||
< | < | ||
postsuper -d ALL | postsuper -d ALL | ||
</ | </ | ||
+ | |||
+ | ===== Delete Messages by Reg-Ex ===== | ||
+ | |||
+ | FIXME Untested! | ||
+ | |||
+ | http:// | ||
+ | |||
+ | ==== postfix-delete.pl script ==== | ||
+ | |||
+ | :!: Once you list queued messages with '' | ||
+ | |||
+ | The following script deletes all mail from the any queue which matches the regular expression specified as the first argument. | ||
+ | |||
+ | < | ||
+ | # | ||
+ | |||
+ | $REGEXP = shift || die "no email-adress given (regexp-style, | ||
+ | |||
+ | @data = qx</ | ||
+ | for (@data) { | ||
+ | if (/ | ||
+ | | ||
+ | } | ||
+ | if($queue_id) { | ||
+ | if (/ | ||
+ | $Q{$queue_id} = 1; | ||
+ | $queue_id = ""; | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | # | ||
+ | open(POSTSUPER," | ||
+ | |||
+ | foreach (keys %Q) { | ||
+ | print POSTSUPER " | ||
+ | }; | ||
+ | close(POSTSUPER); | ||
+ | </ | ||
+ | |||
+ | For example, to delete all queued messages from or to the domain called '' | ||
+ | |||
+ | < | ||
+ | ./ | ||
+ | </ | ||
+ | |||
+ | Delete all queued messages that contain the word '' | ||
+ | |||
+ | < | ||
+ | ./ | ||
+ | </ | ||
+ | |||
+ | ===== Monitoring Postfix Queues ===== | ||
+ | |||
+ | http:// | ||
+ | |||
+ | This script monitors queues and sends an alert via another mail server. | ||
+ | |||
+ | < | ||
+ | #!/bin/bash | ||
+ | # | ||
+ | # Postfix queue length monitoring script (requires msmtp) | ||
+ | # | ||
+ | # This script checks the active, incoming, deferred and maildrop postfix queue directories. | ||
+ | # | ||
+ | # If the number of messages in any of these directories is more than $MAX_QUEUE_LENGTH, | ||
+ | # the script will generate an alert email and send it using msmtp. We use msmtp so that | ||
+ | # we can bypass the local postfix installation (since if the queues are getting big, | ||
+ | # the alert email may not be sent in time to catch the problem). | ||
+ | # | ||
+ | |||
+ | ######################################################### | ||
+ | # SET SCRIPT VARS | ||
+ | ######################################################### | ||
+ | |||
+ | # Path to msmtp binary (e.g. / | ||
+ | MSMTP=/ | ||
+ | |||
+ | # Remote mail host (this is the mail server msmtp will use to send the alert. It should NOT be the local postfix installation) | ||
+ | MAILHOST=backup.mailserver.com | ||
+ | |||
+ | # Remote mail port | ||
+ | MAILPORT=25 | ||
+ | |||
+ | # Mail protocol | ||
+ | MAILPROTO=smtp | ||
+ | |||
+ | # Fully qualified domain name of local postfix installation | ||
+ | DOMAIN=primary.mailserver.com | ||
+ | |||
+ | # From address | ||
+ | MAILFROM=postmaster@mailserver.com | ||
+ | |||
+ | # Recipient (this address should not route to the local postfix installation, | ||
+ | MAILTO=" | ||
+ | |||
+ | # Email subject | ||
+ | MAILSUBJECT=" | ||
+ | |||
+ | # MSMTP log file | ||
+ | LOGFILE=/ | ||
+ | |||
+ | # Root of the postfix queue dirs (e.g. / | ||
+ | QUEUEDIR_ROOT="/ | ||
+ | |||
+ | # Max queue length (if there are more messages in a queue than this number, we will send an alert) | ||
+ | MAX_QUEUE_LENGTH=10 | ||
+ | |||
+ | |||
+ | ######################################################### | ||
+ | # SCRIPT LOGIC STARTS HERE | ||
+ | ######################################################### | ||
+ | |||
+ | # Check msmtp binary exists | ||
+ | if [ ! -f ${MSMTP} ] | ||
+ | then | ||
+ | echo " | ||
+ | exit 1 | ||
+ | fi | ||
+ | |||
+ | # Get the number of messages sitting in each postfix queue directory | ||
+ | Q_ACTIVE=$(find ${QUEUEDIR_ROOT}/ | ||
+ | Q_INCOMING=$(find ${QUEUEDIR_ROOT}/ | ||
+ | Q_DEFERRED=$(find ${QUEUEDIR_ROOT}/ | ||
+ | Q_MAILDROP=$(find ${QUEUEDIR_ROOT}/ | ||
+ | |||
+ | # If any of these queues contain more than $MAX_QUEUE_LENGTH issue an alert | ||
+ | if [ ${Q_ACTIVE} -gt ${MAX_QUEUE_LENGTH} -o ${Q_INCOMING} -gt ${MAX_QUEUE_LENGTH} -o ${Q_DEFERRED} -gt ${MAX_QUEUE_LENGTH} -o ${Q_MAILDROP} -gt ${MAX_QUEUE_LENGTH} ]; then | ||
+ | |||
+ | ( | ||
+ | echo "From: ${MAILFROM} " | ||
+ | echo "To: ${MAILTO} " | ||
+ | echo " | ||
+ | echo ' | ||
+ | echo " | ||
+ | echo "" | ||
+ | echo "One or more of the postfix queues on ${DOMAIN} has grown beyond ${MAX_QUEUE_LENGTH} messages in length." | ||
+ | ) | ${MSMTP} --host=${MAILHOST} --port=${MAILPORT} --protocol=${MAILPROTO} --domain=${DOMAIN} --auth=off --tls=off --from=${MAILFROM} --logfile=${LOGFILE} --syslog=off --read-recipients | ||
+ | |||
+ | exit 2 | ||
+ | |||
+ | fi | ||
+ | |||
+ | exit 0 | ||
+ | </ | ||
+ | |||
+ | ==== Via SNMP ==== | ||
+ | |||
+ | http:// | ||
+ | |||
+ | http:// | ||
+ | |||