PDA

View Full Version : Postfix and multiple domains


xy16644
September 23rd, 2009, 21:11
Currently I have Postfix configured to receive email for one domain name. I have bought another domain name, how do I configure Postfix to send/receive email correctly for the new domain?

I was having a look through some of the options for Postfix, is it called "Virtual Domains"?

If I have two email addresses:

1) test@domain.com

and

2) test@NEWdomain.com

Are these two totally separate mailboxes? Or is it like a mail alias?

I'm just trying to understand the relationship between the two domains being hosted on the mail server.

Appreciate any help. ;)

phospher
September 24th, 2009, 05:22
they can be treated either way depending on configuration. i believe what you are looking for is to use "virtual domains".

have a look at: http://www.postfix.org/VIRTUAL_README.html
and http://www.akadia.com/services/postfix_separate_mailboxes.html

after you read those you should be well on your way. if you want to go the easy route check out "webmin" to administer your postfix config.

xy16644
September 26th, 2009, 12:48
Many thanks for the help.

I have tried to do this in Webmin (yeah yeah I know its cheating! ;-)) but don't seem to be having much luck.

In Webmin I went into the Postfix module and selected Virtual Domains. I then selected "add a new mapping" and typed in my details as follows:

Description: My New Domain
Name: My New Domain
Maps to...: mynewdomain.com

but when I click save mapping it says:

Error while saving a mapping : No map file defined


What am I doing wrong?

phospher
September 27th, 2009, 02:20
sounds like you need to create the map file or define one in your config.

check to see if virtual_mailbox_maps or virtual_alias_maps
exists in the main.cf file. if it's not there, then create the file if it is there then check to make sure it's been created on your file system.

xy16644
September 27th, 2009, 10:09
I went through my main.cf file and I couldn't find any:

virtual_mailbox_maps
virtual_alias_maps


I didn't quite follow your post. Where must I create this map file and what must I call it? What entries must I put in the main.cf file?

Thanks!

phospher
September 28th, 2009, 03:34
you need to edit your main.cf and add:

virtual_alias_domains = DomainOne.com DomainTwo.com
virtual_alias_maps = hash:/etc/postfix/virtual

you then need to run 'postmap' and you may need to restart postfix.

also, i think this is also in the webmin postfix module. you should be able to define the files through there.

xy16644
October 2nd, 2009, 20:49
I added:

virtual_alias_domains = bsdpanic.com privatesovereign.com
virtual_alias_maps = hash:/etc/postfix/virtual


to my main.cf file but when I run postmap it says:

postmap: fatal: usage: postmap [-Nfinoprsvw] [-c config_dir] [-d key] [-q key] [map_type:]file...


I'm not sure what options to use with postmap?

dennylin93
October 3rd, 2009, 01:54
I added:

virtual_alias_domains = bsdpanic.com privatesovereign.com
virtual_alias_maps = hash:/etc/postfix/virtual



Only system configuration files should be under /etc. /usr/local/etc/postfix should be a better place for your configuration.


to my main.cf file but when I run postmap it says:

postmap: fatal: usage: postmap [-Nfinoprsvw] [-c config_dir] [-d key] [-q key] [map_type:]file...


I'm not sure what options to use with postmap?


Try postmap hash:/path/to/file. Remember to run postmap every time the original file is updated.

xy16644
October 3rd, 2009, 11:34
Thanks Denny.

I created a virtual file in:

/usr/local/etc/postfix


I then added the following to my main.cf file:

virtual_alias_domains = privatesovereign.com
virtual_alias_maps = hash:/usr/local/etc/postfix/virtual


I then ran:

postmap hash:/usr/local/etc/postfix/virtual
postfix reload


Is this everything I need to do? Do I need to put anything in the virtual file?

dennylin93
October 3rd, 2009, 15:41
An example configuration:
/usr/local/etc/postfix/main.cf:

virtual_mailbox_domains = example.com
virtual_mailbox_base = /var/vmail
virtual_mailbox_maps = hash:/usr/local/etc/postfix/virtual_mailbox_maps
virtual_uid_maps = static:1000
virtual_gid_maps = static:1000
virtual_alias_maps = hash:/usr/local/etc/postfix/virtual_alias_maps


This first line means that example.com is a virtual domain that Postfix will accept mail for.

In /usr/local/etc/postfix/virtual_mailbox_maps:

foo@example.com example.com/foo/
bar@example.com example.com/bar/


Mails sent to foo@example.com will be sent to /var/vmail/example.com/foo/. Note that the "/" at the end signifies that mail will be stored in the Maildir format.

The virtual mailboxes should have a UID and GID of 1000. Change this as necessary. I have a user called vmail for virtual mailboxes.

Last of all, the alias maps. This is quite similar to the alias file:

foo@example.com bar@example.com


All mail sent to foo@example.com will be forwarded to bar@example.com.

If you're going to create over a hundred accounts, consider using SQL or LDAP as a backend.

The Postfix website (http://www.postfix.org/) has plenty of information. For a in depth view of Postfix, I recommend reading The Book of Postfix (http://nostarch.com/postfix.htm). The book is very informative and useful. The only drawback is that some configuration settings have been replaced by newer ones. However, all changes are documented in the Postfix configuration parameters (http://www.postfix.org/postconf.5.html).

Ruler2112
October 6th, 2009, 00:56
How the mail server treats user@domain1 and user@domain2 is entirely defined by the setup of Postfix. I have a mail server with literally a dozen different domains on it, one for each department. No matter if you send an e-mail to me at domain1 or domain4, they all end up in the same mailbox. I intentionally made it this way so that when people move from department to department, there's no disruption from an e-mail point of view. Mail sent to user@olddepartment arrives in the mailbox set up at user@newdepartment without the employee or myself doing anything. :)

With this configuration, I believe all you have to do is add your new domain to the mydestination variable in main.cf and postmap this file.

If you want user@domain1 to be a different account than user@domain2, you'll need to read and modify your setup as already discussed above.

BeastieBoy
July 3rd, 2010, 23:43
Old thread but still relevant. Isn't it easier to setup aliases for that?

1) edit main.cf and add the hosts to mydestination
2) edit/etc/aliases
3) then regenerate /etc/aliases.db

And voilĂ , all the mail goes to user test no matter the domain name.

BeastieBoy
July 3rd, 2010, 23:46
My bad, you don't even need to setup aliases. Just perform step 1 and restart postfix.