start page | rating of books | rating of authors | reviews | copyrights

sendmail

sendmailSearch this book
Previous: 2.7 Things to Try Chapter 3 Next: 3.2 Role in Local Delivery
 

3. The Roles of sendmail

Contents:
Role in the Filesystem
Role in Local Delivery
Role in Network Transport
Role as a Daemon
Things to Try

The sendmail program plays a variety of roles, all critical to the proper flow of electronic mail. It listens to the network for incoming mail, transports mail messages to other machines, and hands local mail to a local program for local delivery. It can append mail to files and can pipe mail through other programs. It can queue mail for later delivery and understands the aliasing of one recipient name to another.

3.1 Role in the Filesystem

The sendmail program's role (position) in the local file system hierarchy can be viewed as an inverted tree (see Figure 3.1 ).

Figure 3.1: The sendmail.cf file leads to everything else

Figure 3.1

When sendmail is run, it first reads the /etc/sendmail.cf configuration file. Among the many items contained in that file are the locations of all the other files and directories that sendmail needs.

Files and directories listed in sendmail.cf are usually specified as full pathnames for security (such as /var/spool/mqueue rather than mqueue ). As the first step in our tour of those files, run the following command to gather a list of them: [1]

[1] If you are not currently running V8.7 or above sendmail , you will have to grep for "/[^0-9].*/" instead. If you're not running sendmail at all, you won't be able to do this, so for now just read along instead.

% 

grep =/ /etc/sendmail.cf

The output produced by the grep (1) command may look something like the following: [2]

[2] Lines that begin with F or K may also appear. If so, ignore them for now.

O AliasFile=/etc/aliases #O ErrorHeader=/etc/sendmail.oE O HelpFile=/usr/lib/sendmail.hf O QueueDirectory=/var/spool/mqueue O StatusFile=/etc/sendmail.st #O UserDatabaseSpec=/etc/userdb #O ServiceSwitchFile=/etc/service.switch #O HostsFile=/etc/hosts #O SafeFileEnvironment=/arch Mlocal,         P=/bin/mail, F=lsDFMAw5:/|@rmn, S=10/30, R=20/40, Mprog,          P=/bin/sh, F=lsDFMoeu, S=10/30, R=20/40, D=$z:/,

Notice that some lines begin with an O character, some with an M , and others with a # . The O marks a line as a configuration option. The word following the O is the name of the option. The options in the above output show the location of the files that sendmail uses. AliasFile , for example, defines the location of the aliases (5) database. The lines that begin with M define delivery agents . The lines that begin with a # are comments.

First we will examine the files in the O option lines. Then we will discuss local delivery and the files in the M delivery agent lines.

3.1.1 The Aliases File

Aliasing is the process of converting one recipient name into another. One use is to convert a generic name (such as root ) into a real username. Another is to convert one name into a list of many names (for mailing lists).

Take a few moments to examine your aliases file. Its location is determined by the AliasFile option in your sendmail.cf file. For example,

O AliasFile=/etc/aliases

Compare what you find in your aliases file to the brief example of an aliases file listed below:


# Mandatory aliases.
 
postmaster: root
 
MAILER-DAEMON: postmaster
 

 
# The five forms of aliases
 
John_Adams:    adamj
 
xpres:         ford,carter,bush
 
oldlist:       :include: /usr/local/oldguys
 
nobody:        /dev/null
 
ftphelp:       |/usr/local/bin/sendhelp

Your aliases file is probably far more complex, but even so, note that the example shows all the possible forms of aliases.

Lines that begin with # are comments. Empty lines are ignored. As the first comment indicates, there are two aliases that are mandatory in every aliases file. Both are the simplest form of alias: a name and what to change that name into. The name on the left of the : is changed into the name on the right. Names are not case-sensitive. For example, POSTMASTER , Postmaster , and postmaster are all the same. [3]

[3] According to RFC822, all usernames are case-sensitive except postmaster. But sendmail , when processing its aliases file, views all names as case-insensitive.

For every envelope that lists a local user as a recipient, sendmail looks up that recipient's name in the aliases file. (A local user is any address that would normally be delivered on the local machine. That is, postmaster is local, whereas postmaster@remote may not be.) When sendmail matches the recipient to one of the names on the left of the aliases file, it replaces that recipient name with the text to the right of the : character. For example, the recipient postmaster becomes the recipient root .

After a name is substituted, the new name is then looked up, and the process is repeated until no more matches are found. The name MAILER-DAEMON is first changed to postmaster . Then postmaster is looked up again and changed to root . Since there is no entry for root in the aliases file, the mail message is delivered into root 's mailbox.

Every aliases file must have an alias for postmaster that will expand to the name of a real user. [4] Mail about mail problems is always sent to postmaster both by mail-related programs and by users who are having trouble sending mail.

[4] The name postmaster is required by RFC822 and RFC1648, so resist the temptation to redefine it as postperson or sysop .

When mail is bounced (returned because it could not be delivered), it is always sent from MAILER-DAEMON . That alias is needed because users may reply to bounced mail. Without it, replies to bounced mail would themselves bounce.

The five types of lines in an aliases file areas are as follows:


John_Adams:    adamj
 
xpres:         ford,carter,reagan,bush
 
oldlist:       :include: /usr/local/oldguys
 
nobody:        /dev/null
 
ftphelp:       |/usr/local/bin/sendhelp

You have already seen the first (it was the form used to convert postmaster to root ). In the above example, mail sent to John_Adams is delivered to the user whose login name is adamj .

The xpres: line shows how one name can be expanded into a list of many names. Each of those new names becomes a new name for further alias processing. If a name can't be further expanded, a copy of the mail message is delivered to it.

The oldlist: line shows how a mailing list can be read from a file. The expression :include: tells sendmail to read a specific file and to use the names in that file as the list of recipients.

The nobody: line shows how a name can be aliased to a file. The mail message is appended to the file. The /dev/null file listed here is a special one. That file is an empty hole into which the mail message simply vanishes.

The ftphelp: line shows how a name can be replaced by the name of a program. The | character causes sendmail to pipe the mail message through the program whose full pathname follows (in this case, we specified the full pathname as /usr/local/bin/sendhelp ).

The aliases file can become very complex. It can be used to solve many special mail problems. The aliases file is covered in greater detail in Chapter 24, Aliases .

3.1.2 The Queue Directory

A mail message can be temporarily undeliverable for a wide variety of reasons, such as when a remote machine is down or has a temporary disk problem. To ensure that such messages are eventually delivered, sendmail stores them in its queue directory until they can be delivered successfully.

The QueueDirectory option in your configuration file tells sendmail where to find its queue directory:


O QueueDirectory=/var/spool/mqueue

The location of that directory must be a full pathname. Its exact location varies from vendor to vendor, but you can always find it by looking for the QueueDirectory option in your configuration file.

If you have permission, take a look at the queue directory. It may be empty if there is no mail waiting to be sent. If it is not empty, it will contain files like these:

dfQAA07038 dfMAA08000 qfQAA07038 qfMAA08000

When a mail message is queued, it is split into two parts, each part being saved in a separate file. The header information is saved in a file whose name begins with the characters qf . The body of the mail message is saved in a file whose name begins with the characters df .

The example above shows two queued mail messages. One is identified by the unique string QAA07038 and the other by MAA08000 .

The internals of the queue files and the processing of those files are covered in Chapter 23, The Queue .


Previous: 2.7 Things to Try sendmail Next: 3.2 Role in Local Delivery
2.7 Things to Try Book Index 3.2 Role in Local Delivery