Recipe 5.4 Routing Mail for Local Delivery

Problem

You have been asked to configure sendmail to route mail addressed to selected hostnames to specific local user accounts.

Solution

Create mailertable entries that route mail through the local mailer to local user accounts. Process the mailertable text file with makemap to build a hash database.

Create a sendmail configuration that includes the mailertable feature. Here is a sample FEATURE macro:

 dnl Add support for the mailertable FEATURE(`mailertable') 

Rebuild and reinstall sendmail.cf , and then restart sendmail using Recipe 1.8 as a guide.

Discussion

The local mailer delivers mail to users on the local host. For this reason, it does not require the name of a remote host for the host value of the mail delivery triple. Likewise, the host field of a mailertable entry for the local mailer does not contain the name of a remote host. Instead, that field is either blank or it contains a local username. If the host field is blank, the username from the input address is used, and mail is delivered to the local user account of that name. If the host field contains a username, the mail is delivered to that local user. Here are three local mailer mailertable entries ”two with a username and one without:

 support.wrotethebook.com        local:admin sales.wrotethebook.com          local: info.wrotethebook.com           local:pat 

There is no need for physical computers named sales , support, or info , and there probably are no computers with those names. Instead, those names are associated with MX records in the DNS zone file that point to the mail exchanger , and the mailertable entries on the mail exchanger deliver the mail to local user accounts.

A few tests show how these entries affect mail routing. First, a test of the info.wrotethebook.com entry:

 #  sendmail -bv logan@info.wrotethebook.com  logan@info.wrotethebook.com... deliverable: mailer local, host logan@info. wrotethebook.com, user pat 

This test shows how mail addressed to logan@info.wrotethebook.com is handled. The hostname part of this input address matches the key of one of the mailertable entries. The impact of the mailertable process can be seen in the mailer and user values displayed by the sendmail -bv test. [3] The mail is delivered via the local mailer to the local user account pat because pat is specified in the host field of the info.wrotethebook.com mailertable entry. Mail to any user at info.wrotethebook.com is delivered to the local pat account. A second test shows how far the local mailer process can take you:

[3] sendmail passes the local mailer the original delivery address as the host value of the mail delivery triple.

 #  sendmail -bv alana@support.wrotethebook.com  anna@crab.wrotethebook.com... deliverable: mailer esmtp, host crab.wrotethebook.com., user anna@crab.wrotethebook.com andy@rodent.wrotethebook.com... deliverable: mailer esmtp, host rodent.wrotethebook. com., user andy@rodent.wrotethebook.com jane@rodent.wrotethebook.com... deliverable: mailer esmtp, host rodent.wrotethebook. com., user jane@rodent.wrotethebook.com 

In this test, mail is addressed to alana@support.wrotethebook.com . Looking at the mailertable entry for support.wrotethebook.com you might expect the -bv test to display local as the mailer value and admin as the user value. Instead, mail addressed to alana@support.wrotethebook.com is delivered via the esmtp mailer to three different users who are located on external systems. The reason for this is that admin is a mailing list defined in the aliases database. (Mailing lists and the aliases database are discussed in Chapter 2.) The mailertable is not necessarily the end of the delivery process. Aliasing also applies to most mailertable entries that point to the local mailer because the local mailer is usually configured with the F=A mailer flag.

Finally, we test the sales.wrotethebook.com entry, which provides no local username in the return field:

 #  sendmail -bv logan@sales.wrotethebook.com  logan@sales.wrotethebook.com... deliverable: mailer local, host logan@sales. wrotethebook.com, user logan 

In this test, mail is addressed to logan@sales.wrotethebook.com . The mailertable entry tells sendmail to use the local mailer to deliver the mail but does not provide a local username for that delivery. sendmail uses the username from the input address, which, in this case, is logan . The net result is that mail addressed to any user at sales.wrotethebook.com is delivered to a like-named user account on the local host.

Alternatives

Use the virtusertable as an alternative to local mailer mailertable entries that include a username. When no username is defined in the mailertable entry, use the local-host-names file as an alternative to the mailertable to route mail to the local mailer. Placing the hostname sales.wrotethebook.com in the local-host-names file gives the same result as the mailertable entry shown above. This test using configuration Recipe 2.1 illustrates that the local-host-names file is a good alternative solution:

 #  cat >> /etc/mail/local-host-names  sales.wrotethebook.com #  sendmail -bv -Crecipe2-1.cf logan@sales.wrotethebook.com  logan@sales.wrotethebook.com... deliverable: mailer local, user logan 

See Also

Recipe 5.1 to Recipe 5.3 describe additional mailertable features. Recipe 5.6 and Recipe 5.7 describe the virtusertable , which should be evaluated as an alternative to this recipe before it is implemented. Recipe 2.7 covers the aliases database and mailing lists. The sendmail book covers the mailertable in Section 4.8.24. The cf/README file describes the syntax of local mailer mailertable entries.



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