# # Extracted from Newsgroup # Subject: Re: Hostname-based aliasing with smail3.1 ? From: johnl@iecc.com (John R Levine) Date: 1996/08/21 Message-Id: Sender: johnl Organization: I.E.C.C., Trumansburg, N.Y. Newsgroups: comp.mail.smail >mean is if hosta.a.com and hostb.b.com are both aliases for the >same physical host, how can I achieve that mails to abc@hosta.a.com >are aliased to e.g. abc@hostc.c.com and mails to abc@hostb.b.com >are aliased to a different address or even delivered locally ? This seems to be the most asked question in this group. Here's the way I do it. I'll probably make this into a FAQ; comments and suggestions welcome Regards, John Levine, johnl@iecc.com, Trumansburg NY Primary Perpetrator of "The Internet for Dummies" and Information Superhighwayman wanna-be ---cut here--- Setting up virtual domains with smail 3.1. Virtual domains let a single system receive mail for multiple separate domains. That is, it can receive mail for fred@a.com and fred@b.org and treat them differently. This is relatively easy to set up in smail, although it's not all that obvious how to do it. Smail lets you have multiple routers and transports. A router decides how to deliver a message, based on the address domain, and selects a transport. The transport actually does some kind of logically non-local delivery. For virtual domains, I have a transport called "domaint" which delivers to a program which does the actual delivery. My program is a shell script, but you can write your delivery program in any language you want, with perl being the obvious candidate. 1. Set up your DNS records. Create MX records for the virtual domains that point at your smail system. If you don't know what MX records are or how to create them, read "DNS and BIND" by Albitz and Liu, published by O'Reilly. 2. Set up the smail control files. First, do NOT make any changes to your "config" file. In particular, do not list the virtual domains under the hostnames nor the domains in the config file. (Those are synonyms for the local host, not virtual domains.) Add a stanza to your routers file, like this, that recognizes your virtual domains: ------ excerpt from routers file ------ # catch MX domain addresses domains: driver=pathalias, transport=domaint, # deliver using shell script always; # force use even if some other # router gets a more complete match file=domainaddr, # plain ASCII file (unsorted) proto=lsearch, # use linear search optional, # ignore if the file does not exist -required, # no required domains ------- The file "domainaddr" lists the actual virtual domains, like this: .foo.com foo!%s .bar.org bar!$s (Don't indent the lines, but do start each line with a dot unless you want not to handle mail to subdomains like blah.foo.com.) This tells smail to deliver all mail in the foo.com domain via the pseudo-host foo, and in the bar.org domain via the pseudo-host bar, both using the transport domaint. Then add a stanza to your transports file that tells it how to deliver the messages, like this: ------ excerpt from transports file ------ domaint: driver=pipe, max_addrs=1, # one address per invocation max_chars=2000; # at most 2000 chars of addresses cmd="/usr/local/lib/smail/procdomain -f $from -h ${host} ${lc:user}", pipe_as_sender, # have uucp logs contain caller log_output, # save error out for bounce messages ------ This calls the delivery program for each address on each message. If your script is smart enough to handle multiple addresses on a single message, you can set max_addrs to a higher value. (I have a mail to news gateway set up like this, and allowing multiple addresses lets my script post a single cross-posted message rather than several separate copies if the sender puts more than one newsgroup.) 3. Set up your delivery program. If a user sends mail to, say, fred@foo.com, the transport above will run: procdomain -f -h foo fred@foo.com with the entire message, headers and body, on the standard input. My script consists mostly of a big switch to handle all of the various addresses in the various domains. The "-h foo" makes it a little easier to handle addresses like fred@argle.bargle.foo.com, since I can use the value of the -h flag to figure out which domain the address is in and ignore the domain in the address. In my bash script, I set: touser=${1%@*} to strip off the domain, and then switch on $touser@$host, where $host is the value to -h. The $from value passed from smail is really the Sender: field, not the actual author in the From: or Reply-To: field. If you want to send a reponse to the author of the message, you have to parse the headers to get the actual From: or Reply-To: and respond to that. This approach runs all the virtual domains through a single script, which I find works just fine for me, since I manage all of the different domains. You can easily have multiple scripts, e.g.: cmd="/local/proc-${host} -f $from ${lc:user}", to run proc-foo for addresses in foo.com and so forth. The delivery program can do whatever it wants with message. In my script, some addresses are forwarded to local users by feeding the input back to smail, some are autoresponders that send back info files, and some get handed to more sophisticated scripts. Whatever you do, remember that postmaster has to be a valid address in each domain, and it's polite to send back a reasonable error response for unrecognized addresses. I'm happy to get suggestions for improvements to this FAQ, but I can't offer consulting on setting up your particular virtual domains unless you're offering to pay my standard exhorbitant consulting rates. -- John R. Levine, IECC, POB 640 Trumansburg NY 14886 +1 607 387 6869 johnl@iecc.com "Space aliens are stealing American jobs." - Stanford econ prof