Recipe 3.3 Passing Local Mail to a Mail Hub

Problem

You have been asked to create a sendmail configuration that sends all local mail to a mail hub, while directly delivering mail addressed to external systems.

Solution

Create a sendmail configuration containing the MAIL_HUB define to identify the mail relay host for local mail. Use the LOCAL_USER command to exempt the root user 's mail from relaying. Here are sample commands:

 dnl Define a relay server for local mail define(`MAIL_HUB', `smtp.wrotethebook.com') dnl Users whose mail is not passed to the mail hub LOCAL_USER(root) 

Rebuild and reinstall sendmail.cf , and then restart sendmail. Examples of these steps can be found in Recipe Recipe 1.8.

Discussion

The MAIL_HUB define sets a value for the sendmail.cf $H macro. The $H macro identifies a mail hub that sendmail uses to deliver local mail. A few -bv tests show the impact of the MAIL_HUB define:

 #  sendmail -bv tyler@example.com  tyler@example.com... deliverable: mailer esmtp, host example.com, user  tyler@example.com #  sendmail -bv sara@crab  sara@crab... deliverable: mailer esmtp, host crab.wrotethebook.com., user sara@crab. wrotethebook.com #  sendmail -bv craig  craig... deliverable: mailer relay, host smtp.wrotethebook.com, user craig@smtp. wrotethebook.com 

The tests demonstrate that sendmail uses the esmtp mailer to directly deliver mail bound for systems in external domains and external systems in the local domain. Mail that is normally delivered by the local mailer, however, is sent to the mail hub ( smtp.wrotethebook.com ) via the relay mailer.

Notice the user address field of the mail delivery triple displayed by the third test. The address craig has been rewritten to craig@smtp.wrotethebook.com . The address is rewritten even if the delivery address contains the fully qualified name of the local host, for example:

 #  sendmail -bv craig@jamis.wrotethebook.com  craig@jamis.wrotethebook.com... deliverable: mailer relay, host smtp.wrotethebook. com, user craig@smtp.wrotethebook.com 

Thus, all mail that would be delivered by the local mailer, even mail arriving from an external source, is forwarded to the mail hub. When configuring the mail hub, be careful not to forward mail back to a system that relays mail to the hub as this will cause a mail loop.

In this example, the mail hub must be configured with either a craig account or an alias for craig . Often, the mail hub maintains a central mail spool directory and holds the mail for all of its clients. The clients themselves do not have local mail spool directories. They either mount the server's spool directory via NFS, download the mail to a mail reader using POP or IMAP, or read the mail directly on the server.

Because the mail hub has an account or alias for every user on every client, it is important that the usernames on the clients are unique. If Craig Hunt has an account named craig on crab , and Craig Rider has an account named craig on jamis , and both systems use smtp.wrotethebook.com as a mail hub, then both systems will send mail to the hub using the same delivery address craig@smtp.wrotethebook.com , even though the mail is intended for two different users. Using a mail hub requires coordination among all of the clients.

One username that is obviously duplicated on all clients is root . Use the LOCAL_USER macro to ensure that sendmail does not relay mail to the mail hub when the mail is addressed to root . The LOCAL_USER macro adds users to sendmail.cf class $=L . Class $=L is a list of local users whose mail is not relayed to the mail hub.

The following test shows that without the LOCAL_USER macro, mail addressed to the root user is sent to the mail hub:

 #  sendmail -bv root  root... deliverable: mailer relay, host smtp.wrotethebook.com, user root@smtp. wrotethebook.com 

Clearly, sendmail is attempting to forward mail addressed to root to the mail hub. To prevent this, the following line was added to this recipe's configuration:

 LOCAL_USER(root) 

With this command in the configuration, the sendmail -bv test shows the following results:

 #  sendmail -bv root  root... deliverable: mailer local, user root 

The test shows the effect of the LOCAL_USER macro. It keeps root mail local, which is just what we intended. However, before you use the LOCAL_USER macro, make sure that keeping root mail local is correct for your configuration. Often, mail to the root account is routed via an alias to the administrator's real login account. For example, you might route root to alana if Alana is the administrator of this system and alana is the account she uses to login. In that case, you would use an alias and you would not need the LOCAL_USER macro ”although adding the macro would do no harm.

Alternatives

An alternative to MAIL_HUB is the LOCAL_RELAY define. LOCAL_RELAY provides another way to define a mail relay host for mail that is normally delivered by the local mailer. This alternative was rejected because the LOCAL_RELAY define has been deprecated by the sendmail developers for a number of years . When both MAIL_HUB and LOCAL_RELAY are included in the same configuration, they interact in a number of ways. We recommend that you avoid LOCAL_RELAY and use only MAIL_HUB in your configurations.

See Also

Chapter 2 provides extensive examples of using aliases; in particular, Recipe 2.2 provides an example of routing root's mail to another username. Recipe 3.1 also sets a value for the mail hub in the $H macro. The sendmail book covers MAIL_HUB in 4.5.7, LOCAL_USER in 4.5.5, and LOCAL_RELAY in 4.5.5.



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