Using Exim for virtual mail hosts 
6 October 2002
Virtual mail domains can be quite confusing the first time you set them up. It isn’t just you. However, if you keep a few ideas in you head it will become much easier.
First of all, virtual is the key word here. Although you have a number of distinct users for each domain, they all are virtual. For each address in every domain that you have you must also have a distinct local system user. The system doesn’t have any concept of separate domains, it only knows local users. We are going to use a lookup table to convert the local users into their respective domains. The mail transfer authority, in this case Exim, is going to use those tables to route mail accordingly.
For example: if I have joel@afp548.com and joel@pop110.com as virtual mail accounts on my system I have to have two local accounts on my system also. Here is where the confusion begins. In this example I would have two local users on my system with short names of “joel-afp548” and “joel-pop110.” The system sees these two users just like any other users that live on the machine.
When an incoming mail is addressed to “joel@afp548.com,” Exim first breaks the address out into the local part—joel—and the domain, afp548.com. It then looks up the domain in the lookup table. This is handled by the domain router that we include in our default configuration file in our Exim installer but you will need to enable it by uncommenting the appropriate lines. By default Exim will check the /etc/mail/virutal directory for a text file with the same name as the domain. It will look in this file for the local part of the address and then match it up with the appropriate system name. It will then re-run the e-mail with the system name as the address and deliver it to the appropriate place.
If we continue with our example, we have a file in /etc/mail/virtual called afp548.com. In that file we have this line:
joel : joel-afp548@internalroutingonly.org
Exim matches “joel” with “joel” and then swaps “joel-afp548” for it. Now it has a viable local user name to deliver the mail to. The “internalroutingonly.org” is a bit of sleight of hand. Since Exim is going to re-route the e-mail after it looks up the real user, it needs a real address to do this. You can use any domain that you want, even a real routable mail domain. However, it needs to be a non-virtual domain. This means that it can’t have a file in /etc/mail/virtual. Instead the local users will be determined by your system users and /etc/aliases. If we use “imap143.com” as a real domain in our example instead of “internalroutingonly.org” everything would work fine, but since joel-afp548 is a valid user on the system “joel-afp548@imap143.com” would be a valid e-mail addresses. Since most of the time this isn’t what you are looking for it is best to make something up.
Remember, even though this domain doesn’t actually exist you will need to add it to your Exim configure file to let Exim know that it is authoritative for that domain after all. Also once the sleight of hand is done and Exim has a real local user name the actual mail delivery is exactly the same as if you weren’t using local domains.
If we want a forwarding-only user you can actually put a non-local address into the look up file. If that user has mail on another system you won’t need to create a local user for them.
For example:
joel : afp548@mac.com
Would route all e-mail to “joel@afp548.com” to “afp548@mac.com."
Just as with a normal Exim configuration you will need to add each virtual host that you will be using into the Exim config file to let it know it should accept mail for those domains.
If you are using Mac OS X Server 10.2 it is fairly simple to set this up with Exim. If you were to create a local user for “joel@afp548.com” you can keep things simple by using “AFP548.com joel” as the real name and “joel-afp548” and “joel@afp548.com” as the short names. That way all mail is delivered to “joel-afp548” but the user can use “joel@afp548.com” as their user name to pick up the mail.
Resources:
Exim 4.10 as an SMTP agent for Mac OS X Server (part 1 and part 2) www.exim.org