home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


sendmail

sendmailSearch this book
Previous: 23.6 Cause the Queue to Be Processed Chapter 23
The Queue
Next: 23.8 Pitfalls
 

23.7 Process Alternate Queues

The sendmail program provides the ability to use queue directories other than the one listed in the configuration file's QueueDirectory ( Q ) option (see Section 34.8.48 ). Other queue directories can be used to solve an assortment of problems. One example is a site being down for an extended period. When a lot of mail is sent to such a site, messages collect in the queue and eventually start timing out. By moving those messages to a separate queue directory and processing it at a later time (when that site is back up), unnecessary bouncing of mail can be prevented.

Note that the QueueDirectory ( Q ) option is not safe. If its value is changed by anyone other than root , sendmail runs as an ordinary user.

23.7.1 Handling a Down Site

If a site is down, messages to that site can collect in the queue. If the site is expected to be down for a protracted period of time, those queued messages will begin to time out and bounce. To prevent them from bouncing, you can move them to a separate queue directory. Later, when the down site comes back up, you can process that separate queue.

To move the affected messages to a separate queue, you may use a Bourne shell script like the following:

#!/bin/sh
set -u
QUEUE=/var/spool/mqueue
NEWQ=/var/spool/newqueue

if [ ! -d $QUEUE ]
then
        echo "${QUEUE}: Does not exist or is not a directory"
        exit 1
fi
if [ ! -d $NEWQ ]
then
        mkdir -p $NEWQ
        if [ $? -ne 0 ]
        then
                echo "${NEWQ}: Can't create"
                exit 2
        fi
fi
find ${QUEUE} -type f -name qf* -print |\
while read QF
do
        IDENT=`echo $QF | sed -e "s,^${QUEUE}/qf,,"`
        grep "^R" ${QUEUE}/qf${IDENT}
        echo -n "move ${IDENT}? (y/n) "
        read answer
        case $answer in
                [nN]*)  continue;;
                *)      ;;
        esac
        mv ${QUEUE}/*${IDENT} $NEWQ
        if [ $? -ne 0 ]
        then
                echo "Move failed"
                exit 3
        else
                echo "Move succeeded"
        fi
done
/usr/lib/sendmail -OQueueDirectory=${NEWQ} -bp

This script creates a new queue directory, $NEWQ, if it doesn't exist. It then prints the recipient list for each qf file in the queue (the grep (1) in $QUEUE) and asks whether you want to move that file. If you answer yes, all the files that compose the queued message are moved into $NEWQ. After all the messages have been moved, the contents of $NEWQ are printed using the QueueDirectory ( Q ) option:

% 

/usr/lib/sendmail -OQueueDirectory=${NEWQ} -bp

When the down site comes back up at a later time, the messages that have been saved in $NEWQ can be delivered by running the following command by hand:

% 

/usr/lib/sendmail -OQueueDirectory=/var/spool/newqueue -OTimeout.queuereturn=99d -q

The -oTimeout.queuereturn=99d causes the time to live in the queue to be extended to 99 days. This prevents the held mail in ${NEWQ} from wrongly bouncing when you try to deliver it.


Previous: 23.6 Cause the Queue to Be Processed sendmail Next: 23.8 Pitfalls
23.6 Cause the Queue to Be Processed Book Index 23.8 Pitfalls