sendmailSearch this book
Previous: 23.5 How the Queue Is ProcessedChapter 23
The Queue
Next: 23.7 Process Alternate Queues

23.6 Cause the Queue to Be Processed

The sendmail program offers two different methods for processing the queue. It can be told to process the queue periodically or to process it once and then exit.

23.6.1 Periodically with -q

The -q command-line switch is used both to cause the queue to be processed and to specify the interval between queue runs.

A typical invocation of the sendmail daemon looks like this:

/usr/lib/sendmail -bd -q1h

Here, the sendmail program is placed into listening mode with the -bd command-line switch. The -q1h command-line switch tells it to process the queue once each hour. Note that either switch puts sendmail into the background as a daemon. The -bd switch just allows sendmail to listen for incoming SMTP connections. Consider the following:

/usr/lib/sendmail -bd
/usr/lib/sendmail -q1h

This runs two daemons simultaneously. The first listens for incoming SMTP connections. The second processes the queue once per hour.

At small sites, where mail messages are rarely queued, the time interval chosen may be small, to ensure that all mail is delivered promptly. An interval of 15m (15 minutes) may be appropriate.

At many sites an interval of one hour is probably best. It is short enough to ensure that delays in delivery remain tolerable, yet long enough to ensure that queue processing does not overlap.

At large sites with huge amounts of mail and at sites that send a great deal of international mail, the interval has to be carefully tuned by observing how long it takes sendmail to process the queue and what causes that process to take a long time. Points to consider are the following:

23.6.2 From the Command Line

The -q command-line switch, invoked without a time interval argument, is used to run sendmail in queue-processing mode. In this mode, sendmail processes the queue once and then exits. This mode can be run interactively from the command-line or in the background via cron(8).

Other command-line switches can be combined with -q to refine the way the queue is processed. The -v (verbose) switch causes sendmail to print information about each message it is processing. The -d (debugging) switch may be used to produce additional information about the queue. We'll discuss the -v switch as it applies to the queue later in this chapter. Those -d debugging switches appropriate to the queue can be found in Table 37.2 of Section 37.5, "Reference in Numerical Order".

V8 sendmail allows variations on -q: -qI allows you to specify a specific message identifier for processing; -qR allows you to specify specific recipient addresses for processing; -qS allows you to specify specific sender addresses for processing. [7]

[7] IDA and Pre-V8 SunOS sendmail offer three different command-line switches for processing the queue. The -M switch allows you to specify a specific message for processing. The -R switch allows you to specify specific recipient addresses for processing. The -S switch allows you to specify specific sender addresses for processing. Process the queue once: -q

The -q command-line switch, without an interval argument, tells sendmail to process the queue once, then exit. As such, this switch is a handy administrative tool. When the queue fills unexpectedly between queue runs of the daemon, for example, the -q command-line switch can be used to force an immediate queue run:

# /usr/lib/sendmail -q

On machines that do not run the sendmail daemon, the -q command-line switch can be used in conjunction with cron(8) to periodically process the queue. The following crontab(5) file entry, for example, causes sendmail to be run once per hour, at five minutes past the hour, to silently process the queue and exit:

5 * * * * /usr/lib/sendmail -q >/dev/null 2>&1

When used in conjunction with other switches (shown below), the -q switch allows many queue problems to be conveniently handled. Combine -v with -q

The -q switch without an argument prevents sendmail from running in the background and detaching from its controlling terminal. But it also runs silently. To see what is going on, use the -v command-line switch in combination with the -q:

% /usr/lib/sendmail -v -q

The -v command-line switch causes sendmail to print a step-by-step description of what it is doing. To illustrate, consider the following output produced by using both the -v and -q command-line switches:

Running MAA20989 (sequence 1 of 2)
<>... Connecting to via ddn...
Trying Connection timed out during user open with DC.GOV
<>... Deferred: Host DC.GOV is down

Running MAA27002 (sequence 2 of 2)
<>... Connecting to via ddn...
Trying  connected.
220 Sendmail 5.57/3.0 ready at Mon, 27 Jan 92 09:16:38 -0400

Here, two queued messages are being processed. The first fails because of a connection timeout and is requeued for a later queue run. The second succeeds (we omit the full SMTP dialogue). After its delivery is complete, it is removed from the queue. Process by identifier/recipient/sender: -q[ISR]

With V8 sendmail you can process a subset of all queued messages. You can select which to process based on queue identifier, recipient address, or sender address:


The -qI variation is followed by a queue identifier such as KAA34556. The -qR is followed by the address of a recipient. The -qS is followed by the address of a sender. In all three variations there must be no space between the uppercase letter and the identifier or address.

These variations are used to limit the selection of queued files that are processed. For example:

% /usr/lib/sendmail -qSroot -qRbiff@here

Here, the queue is processed once. Only messages from root are processed. Of those, only messages that have biff@here as one of the recipients are processed.

In all three variations a partial specification of queueid, recipient, or sender is viewed by V8 sendmail as a substring. For example,


matches mail from all of the following:


The last line further illustrates that the substring match is a case-insensitive one. The substring match is literal. Wildcard characters (such as *) and regular expressions (such as .*@.*edu) won't work and may confuse the shell from which you run sendmail.

Multiple specifications may be combined on the command line (as shown above), but they all AND together:

% /usr/lib/sendmail -qI123 -qSroot

Here, the queue is processed only for messages with the number 123 anywhere in the message identifier that are also from root and that are also addressed to anyone at

You can use the mailq command to preview the effect of these switches. For example, the following command will list (but not send) the messages that would be processed by the above command line:

% mailq -qI123 -qSroot Process the queue via ESMTP ETRN

The ESMTP ETRN command, based on RFC1985, causes V8.8 and above sendmail to asynchronously process its queue in a manner similar to the -qR command line switch (see Section, "Process by identifier/recipient/sender: -q[ISR]"). This new command allows dial-on-demand sites to make an SMTP connection and to force the other side to process and send any mail that is queued for them. The form of this ESMTP command looks like this:

ETRN hostname

If the host is missing, this error message will be returned:

550 Parameter required

Otherwise, the queue will be processed just as if the following command line argument were given:


In both cases a qf file will be processed if it has a host named hostname anywhere in the host part (following the @) of one of its R lines. The only difference here is that the former (the ETRN) operates asynchronously. That is, sendmail forks a copy of itself, and the forked child processes the queue.

One way to use ETRN is with a simple Bourne shell script:


exit 0

If run on a dial-on-demand host, this script will force a dial-up network connection to be made. The mail server's sendmail is then forced, with ETRN, to process the queue and transport back any mail destined for the local host over the just-created network connection.

Previous: 23.5 How the Queue Is ProcessedsendmailNext: 23.7 Process Alternate Queues
23.5 How the Queue Is ProcessedBook Index23.7 Process Alternate Queues