Posted by Steve on Wed 14 Sep 2005 at 22:31
Handling email for multiple virtual domains is a common server task. Here we'll show how easy that is to manage using the postfix mailserver using just a couple of small configuration changes.
Note: The Debian mail server packages all conflict with each other meaning that it is impossible to have more than one installed at the same time. If you are already using postfix this won't be a problem.
However if you are running a different mailserver, such as exim, be warned that installing postfix will remove it. (Your configuration files should be kept safely in place, but taking a backup in advance is worth doing anyway).
To install postfix run, as root:
apt-get install postfix
Once installed you'll be presented with a simple debconf setup wizard. Proceed by answering the questions as follows:
Now we can move on to the real configuration. What we need to do is two things:
(It is not required that users have local accounts, Postfix offers several alternative virtual hosting approaches - but this is what I use. It is also equivalent to the previous guide on virtual mail handling with exim4)
To tell postfix which domains we will use we will create a text file to list them in, in the directory /etc/postfix/virtual.
(Create that directory by running "mkdir /etc/postfix/virtual").
List all the domains you wish to handle mail for, in the file /etc/postfix/virtual/domains. For example:
example.com example.net example.org
Then to setup the mappings create the file /etc/postfix/virtual/addresses:
example.com DOMAIN email@example.com bob firstname.lastname@example.org steve example.net DOMAIN @example.net steve example.org DOMAIN @example.org chris
This file contains the mappings of email addresses to local accounts. Here we've setup four mappings:
(Note that mail sent to other addresses @example.com will be bounced with "no such user".)
To make these settings live we need to do two things:
In the file /etc/postfix/main.cf add:
mydestination = $myhostname, /etc/postfix/virtual/domains virtual_maps = hash:/etc/postfix/virtual/addresses
That should be all you need to do. Reload postfix by running:
You can test the setup by attempting to send mail to the server, and watching /var/log/mail.info to see what postfix does with the mail.