Posted by Steve on Tue 12 Oct 2004 at 13:50
There are several mail servers available for use with Debian stable; sendmail, postfix and exim to name just three. The default mail server installed is exim3 which is a flexible mail server which will support accepting and sending mail for multiple domains. The setup must be done by hand as the Debian configuration script doesn't handle setting this up. This piece explains how we do just that.
This piece nicely compliments hosting multiple domains with Apache, as you will often want to handle mail and website hosting for multiple domains.
Since Woody was released exim has moved on to version four which is a lot simpler to setup and this can make finding documentation on the older exim3 much harder.
For this setup I'm assuming that you have a Debian woody server setup, which has login accounts for a group of users. These are users you wish to be able to receive email addressed to different domains.
Local user 'steve' wants to get all mail sent to steve.org.uk and debian-administration.org Local user 'paul' wants to get all mail sent to shellcode.org Local user 'bob' wants to get all mail sent to firstname.lastname@example.org Local user 'dave' wants to get all mail sent to email@example.com, firstname.lastname@example.org and email@example.com
This is the kind of virtual mail hosting which is often used in small companies and offered by hosting companies - so called 'catchall' email addresses mean that all email sent to an address at your domain gets sent to your inbox.
To start with we need to look at the exim configuration file which is located in /etc/exim/exim.conf.
We will add some extra sections to this to mention all the domains that this server should accept mail for, then we will add some more lookup files that control where to deliver each incoming mail for the domains.
This allows you to make simple changes to the delivery without touching the main mailserver setup - for example adding new aliases or new users.
There are two places that we need to list the domains in the exim.conf file, the first is in the local_domains section, seperated by colons:
local_domains = localhost:*.steve.org.uk:steve.org.uk:*.debian-administration.org: \ debian-administration.org:*.shellcode.org:shellcode.org:*.bob.com:bob.com
Here we have the domains listed twice "domain.ext" and "*.domain.ext" must both be listed.
Secondly we need to add these domains to the 'userforward' directive as follows:
userforward: driver = forwardfile domains = localhost:*.steve.org.uk:steve.org.uk:*.shellcode.org:shellcode.org: ... other domains too. no_verify check_ancestor file = .forward filter
These two settings tell exim that the domains listed are considered local, so it should handle them, and that alias loops and local forwarding should be accepted for those domains too.
Now we need to add a new section telling Exim where to lookup the actual recipients for mail addressed to each domain. After the 'userforward' section add this new section:
# # This driver handles our virtual domains. It is # last, to avoid unnecessary file lookups for real # local addresses; this is why all of the above # directors have a "domains = " line. virtual: driver = aliasfile domains = partial3-lsearch;/etc/exim/domains no_more file = /etc/exim/$domain_data search_type = lsearch*
This instructs exim to lookup a list of domain names in the file /etc/exim/domains, this file is a list of domains and the file to lookup the real recipient for each incoming message addressed to that domain.
Here's a domain file to match our setup:
*.steve.org.uk: steve.org.uk *.shellcode.org: shellcode.org *.debian-administration.org: debian-administration.org *.bob.com: bob.com
On the left is the domain name, and on the right is a filename from which to take the actual mail recipients. To keep things simple the lookup files are named after the domains. Now we need to create them.
Inside /etc/exim/steve.org.uk we put:
dave: dave@localhost *: steve@localhost
This says that "all mail sent to firstname.lastname@example.org gets delivered to the local user dave. All other mail goes to local user steve".
Setting up the other domains is just as simple. Here is /etc/exim/bob.com:
dave: dave@localhost dave.smith: dave@localhost bob: bob@localhost
Here only three explicit addresses have been created for the bob.com domain - anything else received for example "email@example.com" will be bounced back to the sender.
If you wish to implement catch-all mail handling add the following line to the end of your domain file:
This causes all other mail to be sent to the local user user.
Once you've setup the other domains simpley restart exim with the command /etc/init.d/exim restart.