Recipe 3.4 Passing Apparently Local Mail to a Relay

Problem

Apparently local mail is mail that appears to be addressed to local users (i.e., the delivery address does not contain a hostname portion, yet the mail is not really addressed to a local username). Configure sendmail to send this mail to a mail relay server that is configured to properly handle it.

Solution

Create a sendmail configuration containing a LUSER_RELAY define that identifies the host that can handle apparently local mail. Here is a sample LUSER_RELAY command:

 dnl Define a relay server for apparently local mail define(`LUSER_RELAY', `smtp.wrotethebook.com') 

Rebuild and reinstall sendmail.cf . Restart sendmail to read the new configuration. Recipe 1.8 covers these steps.

Discussion

A delivery address without a hostname is passed to the local mailer for delivery to a local user. If the user portion of the address does not specify a valid local username or alias, the " User unknown" error is returned. The following tests show how this works with a generic configuration:

 #  sendmail -bv fred -Cgeneric-linux.cf  fred... User unknown #  sendmail -bv craig -Cgeneric-linux.cf  craig... deliverable: mailer local, user craig 

craig is a valid username on this host, so the mail is delivered by the local mailer. fred is not a valid local username, so an error is returned. After adding the LUSER_RELAY define to the configuration, mail to craig is delivered as before, but mail to fred is now sent to the mail relay host for delivery:

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

The LUSER_RELAY define sets the value of the sendmail.cf $L macro and adds two rules to the localaddr ruleset (ruleset 5). Ruleset 5 is invoked after a local address is processed through the aliases database. [2] The two rewrite rules added by the LUSER_RELAY define are only executed if the recipient address has not already been resolved to a valid delivery address. The first LUSER_RELAY rewrite rule checks to see if the username from the email address is a key in the user database. If the username is found in the user database, the mail is delivered according to that database's instructions. If the username is not found in the database, the mail is sent to the relay server identified by the $L macro. Thus, if a local delivery address does not resolve to a local username or is not covered by the aliases database or the user database, the mail is sent to the LUSER_RELAY server for delivery.

[2] Ruleset 5 is invoked only when the F=5 flag is set for the selected mailer. By default, this flag is set for the local mailer, which is the mailer used in our examples.

In the last test above, mail addressed to fred is forwarded to the LUSER_RELAY server. The LUSER_RELAY configuration assumes that the server knows how to deliver the mail to fred . Often, this means that the server has a large aliases file that defines how mail is routed to the users. Unlike the MAIL_HUB configuration described in Recipe 3.3, the LUSER_RELAY configuration does not assume that the server maintains a central mail spool directory. The LUSER_RELAY configuration allows the client to deliver some pieces of local mail and sends others to the server for delivery.

An alternative to LUSER_RELAY is to have a large aliases file on the client. This could be a local file or a centrally maintained file accessible via NIS or some other database service. An even more popular alternative is to require users to add the hostname to the email address when the hostname is required for delivery ”in other words, let the users see the "User unknown" error until they understand that they need to address email properly. All of these are viable alternatives.

See Also

Chapter 2 provides examples of both the aliases database and the user database. The sendmail book covers LUSER_RELAY in 4.5.6.



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