Changing load average queue limits
Sendmail allows us to easily queue mail or refuse connections if the server load average becomes too high. Modify the QueueLA and/or RefuseLA options in /etc/mail/sendmail.cf (or /etc/sendmail.cf) as appropriate.
# egrep ‘QueueLA|RefuseLA’ /etc/mail/sendmail.cf
O QueueLA=2
O RefuseLA=6
View domains that we accept mail for
Need to view contents of w class macro, so…
echo ‘$=w’ | sendmail -bt -d0.4
Postfix has it’s postsuper command that allows you to simply remove messages from the queue. There are many reasons why you’d want to do this (being overwhelmed by bounces and spam, for example). Sendmail comes with the qtool.pl script as part of it’s source distribution.
qtool.pl can be put to good use removing stale messages from the mail queue. For example, I regularly remove mail from the queue where connections have timed out with a particular domain. The following script can be modified to remove mail based upon different conditions (just modify the grep regex).
#!/bin/bash
# Script to remove mail destined for a specified domain from the mail queue
AWK="/usr/bin/awk"
BASENAME="/bin/basename"
ECHO="/bin/echo"
GREP="/bin/grep"
MAILQ="/usr/bin/mailq"
QTOOL="/root/qtool/qtool.pl"
SED="/bin/sed"
if [ "$#" -ne "1" ]; then
${ECHO} "Usage: $( ${BASENAME} $0 ) domain.name.here" && exit 1
fi
DOMAIN="$1"
MQUEUE="/var/spool/mqueue"
SENDMAIL_CF="/etc/sendmail.cf"
${ECHO} "WARNING: You are asking me to remove all messages still in"
${ECHO} "the queue where the connection with ${DOMAIN} has timed out."
${ECHO} "Also be warned. This is passed to grep as-is as a regular"
${ECHO} -n "expression. So, are you sure you want to continue? [y|n] "
read RESPONSE
case ${RESPONSE} in
y) : ;;
n) ${ECHO} "Aborting... " >&2 && exit 1 ;;
*) ${ECHO} "Unknown response... " >&2 && exit 1 ;;
esac
${ECHO} "Removing messages for ${DOMAIN}...."
${MAILQ} | ${GREP} -B1 "timed out with ${DOMAIN}" |\
${GREP} '^[a-z]' |\
${AWK} '{print $1}' |\
${SED} 's/\*$//' |\
while read message_id; do
${ECHO} "--[ Removing ${message_id} ]--"
${QTOOL} -C ${SENDMAIL_CF} -d ${MQUEUE}/${message_id}
done
exit 0


