Introduction

Inbound mail is either delivered directly to the addressee or relayed to another mail host for delivery. Mail is directly delivered only if it is destined for the local host; mail destined for any other host is relayed. In this chapter, we look at ways to properly configure sendmail to deliver mail locally and forward it to other systems.

Delivery is a multistep process. First, sendmail must process the host portion of the delivery address and recognize that the mail is, in fact, addressed to the local host. If it isn't addressed to the local host, it is relayed as described in Chapter 3. If it is addressed to the local host, the user portion of the address is processed against the aliases file to determine the proper delivery address. If the aliases file returns an external address, the mail is forwarded to the external host for delivery. If it returns the address of a local mailbox, sendmail checks for a .forward file. If the .forward file exists, the mail is delivered as specified by that file. Otherwise, the mail is delivered to the local mailbox. Figure 2-1 illustrates this delivery flow. [1]

[1] This is a simplified description based on the default configuration. sendmail flags and options can change the way mail delivery is handled.

Figure 2-1. The multistep delivery process
figs/smcb_0201.gif

sendmail processes each delivery address through the canonify ruleset and through the parse ruleset ”rulesets 3 and 0. Aliasing starts when the result of that process tells sendmail to deliver the mail through a mailer that has the A flag set. [2] If ruleset 0 returns the name of a mailer that does not have the A flag set, aliasing is not done. While the A flag can be set for any mailer, only the cyrus mailers and the local mailer set the A flag by default. For our discussion of aliasing, we'll use the local mailer as an example.

[2] Flags are set through the F parameter in each sendmail.cf mailer definition.

Aliasing first looks up the delivery address in the aliases database. If the lookup returns a different email address, the new address is processed. If the mailer used for the new address has the A flag set, that address is looked up in the aliases database. This process continues until no new address is returned by the alias lookup. If the mailer used for the final address returned by the aliases database has the w flag set, sendmail looks for a delivery address in the user's .forward file. By default, only the local mailer has the w flag set. If a .forward file is found, delivery is made based on the delivery address that it contains.

Although Figure 2-1 portrays a simplified version of the actual delivery process, it does highlight areas of the configuration that relate to local delivery and forwarding. Class $=w must be properly configured. The aliases file must be created and made into a database, and, if used, the .forward files must be properly configured.

sendmail only accepts mail for local delivery that is addressed to the local host. All other mail is relayed. Class $=w contains all of the valid hostnames for the local host. If the hostname from the delivery address is found in class $=w , the mail is accepted for local delivery. In fact, ruleset 0 uses class $=w when selecting the local mailer.

Mail delivered by the local mailer must be addressed to a user account that exists on the local host or to an alias that resolves to a valid delivery address. The aliases database frees the local mailer from the limitation of having all local mail addressed to actual usernames. It makes sendmail a more flexible system by allowing mail addressed to a single alias to be sent to multiple recipients or mail addressed to several different names to be routed to a single recipient. The aliases database is also used to forward mail to other computers, programs, and files.

The aliases database is so essential to the functioning of a sendmail system that sendmail complains if the database does not exist. Some users and programs that send out email alerts may also complain because they assume that certain aliases exist. Additionally, if neither the aliases database nor the aliases text file is found, sendmail will not apply the user's .forward file.

When sendmail looks up a local address in the aliases database and no new recipient address is returned by the lookup, sendmail checks to see if the user identified by the local address has a .forward file. The possible locations of the user's .forward file are defined in the sendmail.cf file by the ForwardPath option:

 $  grep ForwardPath sendmail.cf  O ForwardPath=$z/.forward.$w+$h:$z/.forward+$h:$z/.forward.$w:$z/.forward 

The path shown above was configured by the confFORWARD_PATH define in the domain/generic.m4 file used in the sample configuration described in Recipe 1.8. The ForwardPath in this example includes three sendmail.cf macros. The $z macro holds the path of the recipient's home directory, as specified in /etc/passwd . The $w macro holds the primary name of the local host. The $h macro normally holds the name of the recipient host when ruleset 0 constructs the mailer/host/user delivery triple. In this case, however, the mailer is the local mailer so the host is always the local host. This makes the $h macro available for other uses. procmail provides one example of how the $h macro can be used in other ways. For example, when the user + detail addressing syntax is used and procmail is used as the local mailer, the $h macro contains the detail value. [3]

[3] In the configuration created in Recipe 1.8, procmail is used as the local mailer because the linux.m4 file used in that configuration contains the local_procmail feature.

Given this specific ForwardPath , if the local mailer is procmail , the hostname is chef , and the mail is addressed to kathy +cookbook , the following .forward files are searched: /home/kathy/.forward.chef+cookbook , /home/kathy/.forward+cookbook , /home/kathy/.forward.chef , and /home/kathy/.forward . Each file is looked for in order, and the search stops as soon as a file with the specified name is found.

Both the aliases database and .forward files are capable of forwarding mail. Forwarding and relaying are often confused , particularly when mail is forwarded to an external host. When it is, the effect is essentially the same as relaying to that host ”mail is passed to an external system for delivery. The difference is this: mail is forwarded only after it has been accepted for local delivery; mail is relayed when it is not accepted for local delivery. Relaying is covered in Chapter 3.



Sendmail Cookbook
sendmail Cookbook
ISBN: 0596004710
EAN: 2147483647
Year: 2005
Pages: 178
Authors: Craig Hunt

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net