4. How to Run sendmail
One way to run
sendmail
is to provide it with the name of a recipient as the only
command-line argument. For example, the following
sends a mail message to
%
Multiple recipients can also be given.
For example,
the following sends a mail message to
%
The
sendmail
program accepts
two different kinds of command-line arguments.
Arguments that
do not
begin with a
4.1 Become a Mode (-b)
The
sendmail
program can function in a number of different ways
depending on which form of
The effects of some of the options in Table 4.2 can also be achieved by running the sendmail executable using different names. Those names and a description of their results are shown in Table 4.3 . Each name can be a hard link with, a symbolic link to, or a copy of sendmail .
4.1.1 Daemon Mode (-bd)The sendmail program can run as a daemon in the background, listening for incoming mail from other machines. The sendmail program reads its configuration file only once, when it first starts as a daemon. It then continues to run forever, never reading the configuration file again. As a consequence, it will never see any changes to that configuration file. When you change something in the sendmail.cf configuration file, you always need to kill and restart the sendmail daemon. But before you can kill the daemon, you need to know how to correctly restart it. This information is in the /etc/sendmail.pid file or one of your system rc files. On a Berkeley UNIX-based system, for example, the daemon is usually started like this:
/usr/lib/sendmail -bd -q1h
The The actual command to start the sendmail daemon on your system may be different from what we've shown. If you manage many different brands of systems, you'll need to know how to start the daemon on all of them. 4.1.1.1 Kill and restart, beginning with V8.7Killing and restarting the sendmail daemon became easier beginning with V8.7. A single command [2] will kill and restart the daemon:
% This single command has the same effect as the two commands shown for V8.6 below. 4.1.1.2 Kill and restart, with V8.6Before you can start the sendmail daemon, you need to make sure there is not a daemon running already. Beginning with V8.6, the pid of the currently running daemon is found in the first line of the /etc/sendmail.pid file. The processes of killing the daemon looks like this:
After killing the currently running daemon, you can start a new daemon with the following simple command:
4.1.1.3 Kill and restart, old versionsUnder old versions of sendmail you need to use the ps (1) program to find the pid of the daemon. How you run ps is different on BSD UNIX and System V UNIX. For BSD UNIX the command that you use and the output that it produces resemble the following:
Here the leftmost number printed by
ps
(the For System V-based systems you use different arguments for the ps command, and its output differs:
Under old versions of sendmail you must look in your system rc files for the way to restart sendmail . We showed how to find this information in Chapter 3, The Roles of sendmail (see Section 3.4, "Role as a Daemon" ). 4.1.1.4 If you forget to kill the daemonIf you forget to kill the daemon before starting a new one, you may see a stream of messages similar to the following, one printed every 5 seconds (probably to your console window):
getrequests: cannot bind: Address already in use getrequests: cannot bind: Address already in use getrequests: cannot bind: Address already in use getrequests: cannot bind: Address already in use getrequests: cannot bind: Address already in use getrequests: cannot bind: Address already in use getrequests: cannot bind: Address already in use getrequests: cannot bind: Address already in use getrequests: cannot bind: Address already in use getrequests: cannot bind: Address already in use getrequests: cannot bind: Address already in use opendaemonsocket: server SMTP socket wedged: exiting This shows that the attempt to run a second daemon failed. [3]
4.1.2 Show Queue Mode (-bp)
The
sendmail
program can also
display the contents of its queue directory. It
can do this in two ways: by running as a program named
mailq
or by being run as
sendmail
with the
Mail queue is empty If, on the other hand, there is mail waiting in the queue, the output is far more verbose, possibly containing lines similar to these:
.ps 8 Mail Queue (1 requests) -Q-ID-- -Size- --Q-Time--- ------Sender/Recipient------ GAA29775* 702 Thu Mar 12 16:51 <you@here.us.edu> Deferred: Host fbi.dc.gov is down <george@fbi.dc.gov>
Here, the output produced with the
The first
line shows details about the message and the sender. The
A second line may appear giving a reason for failure (if there was one). A message may be queued intentionally or because it couldn't be delivered. The third and possibly subsequent lines show the addresses of the recipients.
The output produced by the 4.1.3 Rebuild Aliases Mode (-bi)Because sendmail may have to search through thousands of names in the aliases file, a version of the file is stored in a separate dbm (3) or db (3) database format file. The use of a database significantly improves lookup speed.
Although
sendmail
can automatically update the database
whenever the
aliases
file is changed, there will be times
when you will want to rebuild it yourself.
You do this either by running
sendmail
using
the command
newaliases
or with the
There will be a delay while sendmail rebuilds the aliases database; then a summary of what it did is printed:
/etc/aliases: 859 aliases, longest 615 bytes, 28096 bytes total
This line shows that the database
was successfully rebuilt. Beginning with V8.6
sendmail
, multiple alias files
became possible, so each line (and there might be many) begins with the
name of an alias file. The information then displayed is the number
of aliases processed, the size of the biggest entry
to the right of the The aliases file and how to manipulate it are covered in Chapter 24, Aliases . 4.1.4 Verify Mode (-bv)
A handy tool for checking aliases
is the To illustrate, consider the following aliases file:
Although you can figure out what the name
In addition to expanding aliases, the
root: fred,larry
Assume that the user
%
This tells
sendmail
to verify the name
larry... User unknown fred... deliverable: mailer local, user fred | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|