[ Previous | Next | Contents | Glossary | Home | Search ]
AIX Version 4.3 System Management Guide: Communications and Networks

Managing the Mail Queue Files and Directories

The mail queue is a directory that stores data and controls files for mail messages that the sendmail command delivers. By default, the mail queue is /var/spool/mqueue.

Mail messages may be queued for several reasons. First, the sendmail command can be configured to process the queue at certain intervals, rather than immediately. If this is so, mail messages must be stored temporarily. Second, if a remote host does not answer a request for a mail connection, the mail system queues the message and tries again later.

Printing the Mail Queue

The contents of the queue can be printed using the mailq command (or by specifying the -bp flag with the sendmail command).

This produces a listing of the queue IDs, the size of the message, the date the message entered the queue, and the sender and recipients.

Mail Queue Files

Each message in the queue has a number of files associated with it. The files are named according to the following conventions:

TypefID

where ID is a unique message queue ID, and Type is one of the following letters indicating the type of file:

d The data file containing the message body without the heading information.
q The queue-control file. This file contains the information necessary to process the job.
t A temporary file. This file is an image of the q file when it is being rebuilt. It is quickly renamed to the q file.
x A transcript file that exists during the life of a session and shows everything that happens during that session.

For example, if a message has a queue ID of AA00269, the following files are created and deleted in the mail queue directory while the sendmail command tries to deliver the message:

dfAA00269 Data file
qfAA00269 Control file
tfAA00269 Temporary file
xfAA00269 Transcript file

q Control File

The q control file contains a series of lines, each beginning with a code letter:

B Specifies the body type . The remainder of the line is a text string defining the body type . If this field is missing, the body type is assumed to be undefined, and no special processing is attempted. Legal values are 7BIT and 8BITMIME.
C Contains the controlling address. The syntax is localuser:aliasname. Recipient addresses following this line are flagged so that deliveries will run as the localuser (a user name from the /etc/passwd file); aliasname is the name of the alias that expanded to this address (used for printing messages).
F Contains flag bits represented as one letter per flag. Defined flag bits are r indicating that this is a response message and w indicating that a warning message has been sent announcing that mail has been delayed.
H Contains a heading definition. There may be any number of these lines. The order in which the H lines appear determines their order in the final message. These lines use the same syntax as heading definitions in the /etc/sendmail.cf configuration file.
I Specifies the i-number of the data file; this can be used to recover your mail queue after a disk crash.
K Specifies the time (as seconds) of the last delivery attempt.
M Contains a message printed by the mailq command. It is mainly used to store status information.
N Specifies the total number of delivery attempts.
O Specifies the original message transfer system (MTS) value from the Ethernet Simple Mail Transfer Protocol (SMTP) transaction. Used for Delivery Status Notifications only.
P Contains the priority of the current message. The priority is used to order the queue. Higher numbers mean lower priorities. The priority increases as the message sits in the queue. The initial priority depends on the message class and the size of the message.
Q Contains the original recipient as specified by the ORCPT= field in an SMTP transaction. Used exclusively for Delivery Status Notifications. It applies only to the immediately following "R" line.
R Contains a recipient address. There is one line for each recipient.
S Contains the sender address. There is only one of these lines.
T Contains the message creation time used to compute when to time out the message.
V Specifies the version number of the queue file format used to allow new sendmail binaries to read queue files created by older versions. Defaults to version zero. Must be the first line of the file, if present.
Z Specifies the original envelope ID (from the SMTP transaction). Used for Delivery Status Notifications only.
$ Contains a macro definition. The values of certain macros ($r and $s) are passed through to the queue run phase).

The q file for a message sent to amy@zeus would look similar to:

P217031 
T566755281 
MDeferred: Connection timed out during user open with zeus 
Sgeo 
Ramy@zeus 
H?P?return-path: <geo> 
Hreceived: by george (0.13 (NL support)/0.01) 
        id AA00269; Thu, 17 Dec 87 10:01:21 CST 
H?D?date: Thu, 17 Dec 87 10:01:21 CST 
H?F?From: geo 
Hmessage-id: <8712171601.AA00269@george> 
HTo: amy@zeus 
Hsubject: test

Where:

P217031 Priority of the message
T566755281 Submission time in seconds
MDeferred: Connection timed out during user open with zeus
                          Status message
Sgeo ID of the sender
Ramy@zeus ID of the receiver
HLines Header information for the message

Specifying Time Values in sendmail

To set the message time-out and queue processing interval, you must use a specific format for the time value. The format of a time value is:

-qNumberUnit

where Number is an integer value and Unit is the unit letter. Unit may have one of the following values:

s Seconds
m Minutes
h Hours
d Days
w Weeks

If Unit is not specified, the sendmail daemon uses minutes (m) as the default. Here are three examples illustrating time-value specification:

/usr/sbin/sendmail -q15d

This command tells the sendmail daemon to process the queue every 15 days.

/usr/sbin/sendmail -q15h

This command tells the sendmail daemon to process the queue every 15 hours.

/usr/sbin/sendmail -q15

This command tells the sendmail daemon to process the queue every 15 minutes.

Forcing the Mail Queue

In some cases, you may find that the queue is clogged for some reason. You can force a queue to run using the -q flag (with no value). You can also use the -v flag (verbose) to watch what happens:

/usr/sbin/sendmail -q -v

You can also limit the jobs to those with a particular queue identifier, sender, or recipient using one of the queue modifiers. For example, -qRsally restricts the queue run to jobs that have the string sally in one of the recipient addresses. Similarly, -qSstring limits the run to particular senders, and -qIstring limits it to particular queue identifiers.

Setting the Queue Processing Interval

The interval at which the sendmail daemon processes the mail queue is determined by the value of the -q flag when the daemon starts.

The sendmail daemon is usually started by the /etc/rc.tcpip file, at system startup. The /etc/rc.tcpip file contains a variable called the queue processing interval (QPI), which it uses to specify the value of the -q flag when it starts the sendmail daemon. By default, the value of qpi is 30 minutes. To specify a different queue processing interval:

  1. Edit the /etc/rc.tcpip file with your favorite editor.

  2. Find the line that assigns a value to the qpi variable, such as:
    qpi=30m
  3. Change the value assigned to the qpi variable to the time value you prefer.

These changes will take effect at the next system restart. If you want the changes to take effect immediately, stop and restart the sendmail daemon, specifying the new -q flag value. See "Stopping the sendmail Daemon" and "Starting the sendmail Daemon" for more information.

Moving the Mail Queue

When a host goes down for an extended period, many messages routed to (or through) that host may be stored in your mail queue. As a result, the sendmail command spends a long time sorting the queue, severely degrading your system's performance. If you move the queue to a temporary place and create a new queue, the old queue can be run later when the host returns to service. To move the queue to a temporary place and create a new queue:

  1. Stop the sendmail daemon by following the instructions in "Stopping the sendmail Daemon".

  2. Move the entire queue directory by entering:
    cd /var/spool 
    mv mqueue omqueue
  3. Restart the sendmail daemon by following the instructions in "Starting the sendmail Daemon".

  4. Process the old mail queue by entering:
    /usr/sbin/sendmail -oQ/var/spool/omqueue -q
    The -oQ flag specifies an alternate queue directory. The -q flag specifies to run every job in the queue. To get a report about the progress of the operation, use the -v flag.
    Note: This operation can take a long time.
  5. Remove the log files and the temporary directory when the queue is empty by entering:
    rm /var/spool/omqueue/* 
    rmdir /var/spool/omqueue

Starting the sendmail Daemon

To start the sendmail daemon, enter either of the following commands:

startsrc -s sendmail -a "-bd -q15"

OR

/usr/lib/sendmail -bd -q15

If the sendmail daemon is already active when you enter one of these commands, you will see the following message on the screen:

The sendmail subsystem is already active. Multiple instances are not supported.

If the sendmail daemon is not already active, then you will see a message indicating that the sendmail daemon has been started.

Stopping the sendmail Daemon

To stop the sendmail daemon, execute the stopsrc -s sendmail command. If the sendmail daemon was not started with the startsrc command:


[ Previous | Next | Contents | Glossary | Home | Search ]