D. J. Bernstein
Internet mail
qmail
Frequently asked questions

Routing incoming messages by host


How do I receive mail for another host name? I'd like our disk server to receive mail addressed to af.mil. The disk server has IP address 18.25.0.1.

Answer: Add af.mil to /var/qmail/control/locals, and tell qmail to read locals. Add af.mil to /var/qmail/control/rcpthosts.

Make sure that there is an appropriate MX record in DNS for af.mil. Here's how to create the MX record using tinydns:

     cd /etc/tinydns/root
     ./add-mx af.mil 18.25.0.1
     make
If you're using BIND, put
     af.mil. IN MX 0 a.mx.af.mil.
     a.mx.af.mil. IN A 18.25.0.1
into the appropriate zone file. signal BIND to reload, and check for errors in the appropriate system log. Don't forget the trailing dots.
How do I set up a virtual domain? I'd like any mail for nowhere.mil, including root@nowhere.mil and postmaster@nowhere.mil and so on, to be delivered to Bob. I've set up the MX already.

Answer: Add nowhere.mil:bob to /var/qmail/control/virtualdomains, and tell qmail to read virtualdomains. Add nowhere.mil to /var/qmail/control/rcpthosts.

Now mail for whatever@nowhere.mil will be delivered locally to bob-whatever. Bob can set up ~bob/.qmail-default to catch all the possible addresses, ~bob/.qmail-info to catch info@nowhere.mil, etc.


How do I set up several virtual domains for one user? Bob wants another virtual domain, everywhere.mil, but he wants to handle nowhere.mil users and everywhere.mil users differently. How can we do that without setting up a second account?

Answer: Add two lines to /var/qmail/control/virtualdomains:

     nowhere.mil:bob-nowhere
     everywhere.mil:bob-everywhere
Tell qmail to read virtualdomains. Add both nowhere.mil and everywhere.mil to /var/qmail/control/rcpthosts. Now Bob can set up separate .qmail-nowhere-* and everywhere-* files. He can even set up .qmail-nowhere-default and .qmail-everywhere-default.
How do I organize a big network? I'm in charge of the 18.25 network. I have a lot of machines, and I don't know where to start.

Answer: First, choose the domain name where your users will receive mail. This is normally the shortest domain name you control. If you are in charge of *.movie.edu, you can use addresses like joe@movie.edu.

Second, choose the machine that will publish IP address information for movie.edu. Install a DNS server on that machine. Configure the server to handle movie.edu and 25.18.in-addr.arpa. For example, if you are using the tinydns server from the djbdns package:

     cd /etc/tinydns/root
     ./add-ns movie.edu 18.25.0.1
     ./add-ns 25.18.in-addr.arpa 18.25.0.1
     make
Here 18.25.0.1 is the IP address of the machine. If you're using BIND instead of tinydns, you will have to create new movie.edu and 25.18.in-addr.arpa zone files, each with SOA and NS records.

Third, for each machine on your network, create a host name in DNS:

     cd /etc/tinydns/root
     ./add-host bobshost.movie.edu 18.25.0.57
     make
(You can do a series of add commands and then a final make.) If you're using BIND instead of tinydns, you'll have to create an A record for each machine in the movie.edu zone file, and a PTR record for each machine in the 25.18.in-addr.arpa zone file.

Fourth, choose a mail exchanger, i.e., a machine that will know what to do with mail for different users at movie.edu. Set up an MX record in DNS to deliver movie.edu messages to the mail exchanger:

     cd /etc/tinydns/root
     ./add-mx movie.edu 18.25.0.2
     make

Fifth, install qmail on the mail exchanger. Put movie.edu into /var/qmail/control/rcpthosts so that the machine will accept messages for users at movie.edu. Put

     movie.edu:alias-movie
into /var/qmail/control/virtualdomains.

Sixth, make a list of machines where mail should end up, and create ~alias/.qmail-movie-user files on the mail exchanger forwarding messages to those machines. For example, if mail for Bob should end up on Bob's workstation, put

     bob@bobshost.movie.edu
into ~alias/.qmail-movie-bob. Do the same for other users. If you have many users, you should set up these aliases with fastforward instead.

Seventh, install qmail on each machine where mail should end up. On bobshost.movie.edu, for example, qmail will automatically configure itself to accept messages for bob@bobshost.movie.edu and deliver them to Bob's mailbox on bobshost.

Eighth, on all your machines, put movie.edu into /var/qmail/control/defaulthost, so that Bob's outgoing mail uses an address of bob@movie.edu.

Scalability notes: You can replicate DNS service across several machines to spread the incoming DNS load. You can replicate mail aliases across several mail exchangers to spread the incoming mail load. You can use tinydns to provide addresses for a huge number of mail exchangers, and optionally to try to select an address close to the client.