Apache Server Survival Guide asgxb.htm

Previous Page TOC Next Page



B


Managing Virtual Domains with sendmail V8


The technique described in this chapter will help you map e-mail addresses to a system mailbox. While in most installations you won't have to worry about this because UNIX will handle this for you, more complex installations that make use of virtual domains will probably require you to provide some sort of e-mail address support.

An Internet e-mail address can be divided into two components: the username and the domain name (user@domain.dom).

The user portion usually matches the login name of a local user. It can also be an alias to a different user or a distribution list for many other users in the system. As you may be aware, you cannot create two identical login names on the same machine under UNIX. It would also be unwise to create an alias that matched an existing user's login name. If you did create such an inconsistency, the results will be unexpected and more than likely not be what you want. Mail addressed to the user will end up delivered to someone else.

While under typical installation, this is never a problem. When it comes to dealing with virtual domain names and virtual Web sites, it's like you will run into a problem. Someone responsible for handling e-mail for one of your virtual domains will want you to provide the ability to redirect mail written to user@his.domain to be mapped to his e-mail account on your system or forwarded elsewhere. For addresses such as webmaster@domain.com, you can easily see the problem. sendmail, by default, doesn't make a distinction between e-mail accounts destined to different domains. To sendmail, if the domain in question is not forwarded elsewhere, it must belong to the user addressed in the envelope, regardless of the domain name.

The following article is reprinted and enhanced from a posting made on November 10, 1995, to comp.mail.sendmail by Johan Svensson (<johan@jos.net>). He granted kind permission for the inclusion of this article. It describes how to handle this situation by allowing each domain to have standard e-mail addresses, which are forwarded to the appropriate user based on the domain name information.

Managing Several Domains


If you want to provide e-mail to several domains and be able to use identical usernames across different domains such as in


user@a.dom.ain mb1@dom.ain

user@b.dom.ain mb2@dom.ain

user@c.dom.ain mb@outer.space

you'll need a way to map the full e-mail address to use an external database. You will also need to do some minor Ruleset rewriting in the sendmail.cf. Many Internet Service Providers have asked for a general solution to this problem, and here's the solution.

This process involves two major steps:

  1. 1. Creating a database to map from an e-mail address to a mailbox.

  2. 2. Modifying a sendmail ruleset so that it uses the e-mail to mailbox database to figure out where to deliver the e-mail.


Building the Database


The database is compiled out of an American Standard Code of Information Interchange (ASCII) file that has the following structure (the incoming e-mail address and the destination mailbox, which can be in a totally different system or machine):


user@a.dom.ain mb1@dom.ain

user@b.dom.ain mb2@dom.ain

user@c.dom.ain mb@outer.space

The left column contains the e-mail address of a particular user, and the right column contains the corresponding mailbox. If you maintain several domains, you may want to create several databases (one per domain) and cat them together (using the UNIX cat program) prior to compilation. This may make it easier to maintain domain aliases for a domain in the future because maps for each domain are saved on their own file.

The following example may closely match your needs. Some of the destination addresses are forwarded to other domains for resolution (webmaster@client2.se). Others will be remapped to other addresses that will require reprocessing and derefencing the address several times before arriving at the final mailing address (webmaster@client1.se):


webmaster@josnet.se wm.list@eowyn.josnet.se

webmaster@client1.se joe@client1.se

webmaster@client2.se anne@another.provider.se

webmaster@client3.se joe@client3.se

joe@client1.se c1_joe@mail.josnet.se

joe@client3.se joeuser

Note that you need to write the complete e-mail address in the left column. The right column entry can be a local address (for example johan if that account exists) or a complete e-mail address on another system (or a domain the server recognizes as local).

After you build the ASCII representation of the database, you'll need to compile it into a more efficient lookup table using the makemap utility that came with your sendmail distribution (if your system supports hash, dbm or btree, you can use those commands instead). Your command will look something like the following:


makemap hash mbt.db <mbt

The resulting hashed database in this example is called mbt.db. The input ASCII database is called mbt.

Configuring sendmail to Use the Mailbox Database


In /etc/sendmail.cf, add the following line right after the DM entry. You'll need to replace method with the type of database it is (use hash for makemap files, dbm -o for dbm files, or btree for a btree-generated databases):


Kmbt method /etc/sendmail/mbt.db

Editing the Rulesets

Edit the ruleset 98 section (S98) and add the following inside the ruleset. Which modifications you make will depend on the version of sendmail you are using.

For sendmail versions prior to 8.7.1, add the following:


R$+ < @ $+ . > $: $1 < @ $2 > .

R$+ < @ $+ > $* $: $(mbt $1@$2 $: $1 < @ $2 > $3 $)

R$+ < @ $+ > $* $: $(mbt $2 $: $1 < @ $2 > $3 $)

R$+ < @ $+ > . $: $1 < @ $2 . >

For sendmail versions later than 8.7.1, add this instead:


R$+< $+. > $1< $2 >

R$+< $+ > $: < > $(mbt $1$2 $)

R< > $+ @ $* $: < $1 > $(mbt * @ $2 $)

R< > $* $: $>3 $1

Restarting sendmail


Finally, restart sendmail to see your changes. You must do this in order to reread the configuration file and test with sendmail -bv or sendmail -bt.

Summary


This technique will make it easier for you to support multiple info and webmaster mailboxes for the various domains you host. Because the various mapping are external to the sendmail configuration file, adding and deleting entries are much easier to maintain than would otherwise be possible.

Previous Page Page Top TOC Next Page