User Tools

Site Tools


internet:mail:postfix_queue_mgmt

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
internet:mail:postfix_queue_mgmt [2013/03/03 12:38]
gcooper created
internet:mail:postfix_queue_mgmt [2018/11/02 07:11] (current)
gcooper
Line 4: Line 4:
  
 http://blog.gtuhl.com/2008/08/14/basic-postfix-queue-management http://blog.gtuhl.com/2008/08/14/basic-postfix-queue-management
 +
 +http://postfixmail.com/blog/index.php/manage-mail-in-the-deferred-queue/
  
 These systems use Postfix as the MTA: These systems use Postfix as the MTA:
Line 10: Line 12:
   * Zimbra   * Zimbra
  
 +===== View Mail Queues =====
 +
 +<file>
 +postqueue -p
 +</file>
 +
 +View a particular message:
 +
 +<file>
 +postcat -q <queueID> | head --lines 100
 +</file>
 +
 +===== Track Messages =====
 +
 +<file>
 +grep "Nov 13 06:13:" /var/log/maillog*
 +
 +grep "D233911382F9" /var/log/maillog*
 +</file>
 +
 +===== Deferred Messages =====
 +
 +==== Flush Mail Queues ====
 +
 +  * Default queue_run_delay (interval between send attempts) is 300s or 300 seconds
 +
 +Attempt to send queued mail now:
 +
 +<file>
 +postqueue -f
 +</file>
 +
 +View a deferred message:
 +
 +<file>
 +postcat -q 022412012A | head -40
 +</file>
 +
 +or:
 +
 +<file>
 +postcat /var/spool/postfix/deferred/0/022412012A
 +</file>
 +
 +==== Purge Mail Queues ====
 +
 +To delete all email in the queue from a domain run this command as root:
 +
 +postqueue -p | tail -n +2 | awk 'BEGIN { RS = "" } /@example\.com/ { print $1 }' | tr -d '*!' | postsuper -d -
 +
 +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 = "" } /username@example\.com/ { print $1 }' | tr -d '*!' | postsuper -d - 
 +
 +To delete all queued mail:
 +
 +<file>
 +postsuper -d ALL
 +</file>
 +
 +===== Delete Messages by Reg-Ex =====
 +
 +FIXME Untested!
 +
 +http://www.cyberciti.biz/tips/howto-postfix-flush-mail-queue.html
 +
 +==== postfix-delete.pl script ====
 +
 +:!: Once you list queued messages with ''postqueue -p'' and determine a reg-ex pattern of files you want to delete, you can use the following script to do the deletions.
 +
 +The following script deletes all mail from the any queue which matches the regular expression specified as the first argument.
 +
 +<file>
 +#!/usr/bin/perl
 + 
 +$REGEXP = shift || die "no email-adress given (regexp-style, e.g. bl.*\@yahoo.com)!\n";
 + 
 +@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,"|postsuper -d -") || die "couldn't open postsuper" ;
 + 
 +foreach (keys %Q) {
 +  print POSTSUPER "$_\n";
 +};
 +close(POSTSUPER);
 +</file>
 +
 +For example, to delete all queued messages from or to the domain called ''fackspamdomain.com'', enter:
 +
 +<file>
 +./postfix-delete.pl fackspamdomain.com
 +</file>
 +
 +Delete all queued messages that contain the word ''xyz'' in the e-mail address:
 +
 +<file>
 +./postfix-delete.pl xyz
 +</file>
 +
 +===== Monitoring Postfix Queues =====
 +
 +http://stackoverflow.com/questions/226699/how-to-monitor-postfix-mta-status
 +
 +This script monitors queues and sends an alert via another mail server.
 +
 +<file>
 +#!/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. /usr/bin/msmtp on Debian systems)
 +MSMTP=/usr/bin/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, for obvious reasons)
 +MAILTO="alerts@anotherdomain.com"
 +
 +# Email subject
 +MAILSUBJECT="Postfix queue length alert for ${DOMAIN}"
 +
 +# MSMTP log file
 +LOGFILE=/var/log/msmtp.log
 +
 +# Root of the postfix queue dirs (e.g. /var/spool/postfix on Debian systems). Note: no trailing slash.
 +QUEUEDIR_ROOT="/var/spool/postfix"
 +
 +# 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 "Cannot find ${MSMTP}. Exiting."
 +        exit 1
 +fi
 +
 +# Get the number of messages sitting in each postfix queue directory
 +Q_ACTIVE=$(find ${QUEUEDIR_ROOT}/active -type f | wc -l)
 +Q_INCOMING=$(find ${QUEUEDIR_ROOT}/incoming -type f | wc -l)
 +Q_DEFERRED=$(find ${QUEUEDIR_ROOT}/deferred -type f | wc -l)
 +Q_MAILDROP=$(find ${QUEUEDIR_ROOT}/maildrop -type f | wc -l)
 +
 +# 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 "Mime-Version: 1.0"
 +        echo 'Content-Type: text/plain; charset="iso-8859-1"'
 +        echo "Subject: ${MAILSUBJECT}"
 +        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
 +</file>
 +
 +==== Via SNMP ====
 +
 +http://exchange.nagios.org/directory/Plugins/Email-and-Groupware/Postfix/Postfix-Queue-Monitor/details
  
 +http://www.paessler.com/knowledgebase/en/topic/21223-monitoring-e-mail-queue-on-postfix
  
  
internet/mail/postfix_queue_mgmt.1362339500.txt.gz · Last modified: 2013/03/03 12:38 by gcooper