Previous Table of Contents Next


Printing the Mail Queue

You can print the contents of the queue by specifying the -bp flag to sendmail. Type /usr/lib/sendmail -bp | more and then press Return. A list of the queue IDs, the size of the message, the date the message entered the queue, the message status, and the sender and recipients are displayed. You can also type mailq and then press Return to print the contents of the mail queue.

Format of Queue Files

The sendmail program stores temporary queue files in /var/spool/mqueue. All such queue files have the form xfAA99999, where AA99999 is the ID for the file and x is the type. Table 3-2 shows the types of queue files.

Table 3-2 Types of Queue Files

Type Description
d A data file. The message body (excluding the header) is kept in this file.
l A lock file. If this file is present, the job is currently being processed, and running the queue will not process it. For this reason, an extraneous lock file can make a job seem to disappear.
n This separate file is created whenever an ID is created. It ensures that no mail can ever be destroyed because of a race condition. This file should not exist for more than a few milliseconds at any given time.
q The queue control file. This file contains the information needed to process the job.
t A temporary file. This file is an image of the qf file when it is being rebuilt. When the rebuild is complete, the file is renamed qf.
x A transcript file that exists during the life of a session and shows everything that happens during that session.

The qf file contains a series of lines, each beginning with a code letter, as shown in Table 3-3. See Chapter 4 for more information about qf file codes.

Table 3-3 Codes for the qf File

Code Description
P The current message priority, which is used to order the queue. The higher the number, the lower the priority. The priority increases as the message sits in the queue. The initial priority depends on the message class and the size of the message.
T The job creation/submission time in seconds, which is used to compute when the job times out.
D The name of the data file.
M A message. This line, which is printed by using sendmail with the -bp flag, is generally used to store status information. It can contain any text.
S The sender name.
E Error recipient name. Error messages are sent to this user instead of to the sender. This line is optional.
H A header definition. There may be any number of these lines. The order is important: It represents the order in the final message. The syntax is the same as in the header definitions in the configuration file.
R A recipient name. There is one line for each recipient. The recipient name normally is completely aliased, but it is actually re-aliased when the job is processed. The recipient name must be at the end of the qf file.

The queue is automatically run at the interval specified in the sendmail.cf file. (The default is every hour.) The queue is read and sorted by message priority, and then sendmail tries to process all jobs in order. The sendmail program first checks to see if a job is locked. If locked, it skips the job; if not locked, sendmail processes it.

If a major host goes down for several days, the queue may become prohibitively large, and sendmail will spend lots of time sorting the queue. You can fix this by moving the queue to a temporary place and creating a new queue. You can run the old queue later, when the host is returned to service.

Forcing the Queue

Follow these steps to force the queue to process mail in the queue now:

1.  Become superuser on the mailhost.
2.  Type ps -el | grep sendmail and then press Return. Note the PID for sendmail; you will use it in the next step.
3.  Type kill PID and then press Return. The old sendmail daemon is killed to keep it from trying to process the old queue directory.
4.  Type cd /var/spool and then press Return.
5.  Type mv mqueue omqueue; mkdir mqueue and then press Return. These commands move the directory mqueue and all of its contents to the directory omqueue and then create a new empty mqueue directory.
6.  Type chmod 755; chown daemon; chgrp daemon; mqueue and then press Return. These commands set the permissions of the directory to read/write/execute by others and read/execute by group and by others. They also set the owner and group to daemon.
7.  Type /usr/lib/sendmail -bd -q1h and then press Return. A new sendmail daemon is started, with a queue runtime of one hour.

Running the Old Mail Queue

Follow these steps to run the old mail queue:

1.  Type /usr/lib/sendmail -oQ/var/spool/omqueue -q and then press Return. The -oQ flag specifies an alternate queue directory, and the -q flag says to run every job in the queue. Use the -v flag if you want to see the verbose output displayed on the screen.
2.  When the queue is finally emptied, type rmdir /var/spool/omqueue and then press Return. The empty directory is removed.

You can run a subset of the queue at any time with the -Rstring option (run queue where any recipient name matches string) or with the -Mnnnnn option to sendmail. (Run just one message with queue ID nnnnn.)

To run a subset of the mail queue, type /usr/lib/sendmail -Rstring and then press Return. In this example, everything in the queue for recipient wnj is processed:

oak% /usr/lib/sendmail -Rwnj


Previous Table of Contents Next