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 bob@example.com bob steve@example.com 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
Then run:
postmap /etc/postfix/virtual/addresses
That should be all you need to do. Reload postfix by running:
/etc/init.d/postfix reload
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.
[ Parent ]
[ Parent ]
[ Parent ]
Steve, there seems to be a minor problem with your set up.
warning: do not list domain example.com in BOTH mydestination and virtual_alias_domains
Any ideas?
[ Parent ]
Strange.
The warning there is the same thing you see in the documentation, but in the example (and my live setup) I have:
myhostname = mail.foo.com mydestination = $myhostname, /etc/postfix/virtual/domains
The only way I can see this being a problem is if you list foo.com inside the virtual/domains file - if you do that remove "$myhostname" from the mydestination setting.
Failing that feel free to post your main.cf file to see if there's anything different you've got there.
Steve
--
[ Parent ]
[ Parent ]
postconf -n alias_database = hash:/etc/aliases alias_maps = hash:/etc/aliases append_dot_mydomain = no biff = no config_directory = /etc/postfix inet_interfaces = all mailbox_command = /usr/bin/procmail mailbox_size_limit = 0 mydestination = $myhostname, smtp.$mydomain, mail.$mydomain, /etc/postfix/virtual/domains, localhost, localhost.localdomain mydomain = hoeg.com myhostname = remote.$mydomain mynetworks = 127.0.0.0/8 myorigin = /etc/mailname recipient_delimiter = + relayhost = smtpd_banner = $myhostname NO UCE ESMTP smtpd_delay_reject = no smtpd_helo_required = yes smtpd_recipient_restrictions = permit_mynetworks reject_unauth_destination check_policy_service inet:127.0.0.1:60000 strict_rfc821_envelopes = yes
/etc/postfix/virtual/domains hoeg.com hoeg.org example.com
/etc/postfix/virtual/addresses peter@hoeg.com peter hoeg.org DOMAIN peter@hoeg.org peter example.com DOMAIN abc@example.com peterNo more errors and it works!
[ Parent ]
************************************************ /etc/postfix/main.cf mydestination = $myhostname, /etc/postfix/virtual/domains /etc/postfix/virtual/domains example.com example.net example.org /etc/postfix/virtual/addresses: example.com DOMAIN bob@example.com bob steve@example.com steve example.net DOMAIN @example.net steve example.org DOMAIN @example.org chris ************************************************Quote from http://www.postfix.org/VIRTUAL_README.html:
NEVER list a virtual alias domain name as a mydestination domain! NEVER list a virtual MAILBOX domain name as a mydestination domain! NEVER list a virtual MAILBOX domain name as a virtual ALIAS domain!
[ Parent ]
It's a feature. Older Postfix versions tended to match subdomains in places like main.cf. New versions will require fully qualified domain names.
/etc/postfix/main.cf:mydomains = example.net
virtual_alias_domains = obscure.example.net
To suppress the warning, define the variable
/etc/postfix/main.cf:parent_domain_matches_subdomains =
He's warning you that you might be depending on the old behavior, and you ought to revisit your main.cf and map files.
If the definition of parent_domain_matches_subdomains in postconf(5) does not make sense to you, try changing the first word from "What" to "List of".
[ Parent ]
[ Parent ]
[ Parent ]
[ Parent ]
[ Parent ]
I found the following to be easier than the method suggested here, and since I found this resource a great starting point, I'd like to mention an easier way here.
Add the following to /etc/postfix/main.cf:
virtual_alias_maps = hash:/etc/postfix/virtual
Create /etc/postfix/virtual and add something like:
first.example.com anything
postmaster@first.example.com admin@example.com
webmaster@first.example.com webmaster@www.example.com
second.example.com anything
postmaster@second.example.com admin@somewhereelse.example.com
blast@second.example.com one@example.com, two@example.com, three@example.com
Do the database file dance with: postmap /etc/postfix/virtual
invoke-rc.d postfix reload
Step one is different because it uses virtual_alias_domains instead of the virtual_maps suggested here. It makes the most sense for my application and was learned from "Mail forwarding domains" in the Postfix Virtual Domain Hosting Howto.
Step two can be tricky because the domain.example.com anything lines take the place the place of /etc/postfix/virtual/domain suggested here--letting postfix know what domains destinations it will accept. See the Virtual Alias Domains section of the virtual manpage for a more thorough explanation.
Beauty here is all that is needed is in one file.
Of course, please correct me if I'm wrong! And thanks for this site, and go Debian!
[ Parent ]
[ Parent ]
[ Parent ]
[ Parent ]
Very good (and deeper HOWTO) about postfix, virtual domains and even more is here: http://workaround.org/articles/ispmail-sarge/.
Best Regards,
Luke
[ Parent ]