Search code examples
linuxdovecot

Postfix: which option for multiple domains and multiple users?


Our server will have three domains: example.net, example.org, and example.nl. For each, the info@... and webmaster@... should be working (but can be shared / forwarded to one). For the .org and .nl domains those will be the only users. For the .net domain there will be a few dozen users. The .net domain will be the main address for website and email.

The users will have no SSH access, no mysql access, no ftp access, only mailboxes.

Postfix and Dovecot are running now. Dovecot currently looks at unix account for mailboxes but that can change.

On this page I read about the different options for Postfix: http://www.postfix.org/VIRTUAL_README.html but it's not clear enough to me which is best for us, what the pros and cons are.

I lack the knowledge to make a good choice on which is the best option for us. So: * the .net domain is the main address for website and email * info@ and webmaster@ for .net/.org/.nl should have a mailbox, but it's OK if that's just one mailbox for info@ and one for webmaster@ and the others are forwarded to those info@example.net and webmaster@example.net * users only have name@example.net, I don't care if name@example.org and name@example.nl work or not

Any suggestions?

Thanks!


Solution

  • Before I go and describe how you can do this I must warn you - it is fairly easy to have your postfix server misconfigured which can result making it working as open-relay. Make sure you test it on sites like this: http://mxtoolbox.com/diagnostic.aspx

    Also I would recommend "The book of postfix" by Ralf Hildebrandt and Patric Koetter.

    Now - to the answer.

    Postfix offers functionality called "virtual mailbox". Not to go deep into details - you can list all your domains with virtual_mailbox_domains configuration option within your main.cf; this option works together with virtual_mailbox_maps, virtual_alias_maps and virtual_alias_domains. See example piece of configuration from my main.cf below:

    (...)
    myhostname = main_domain.com
    (...)
    virtual_mailbox_domains = domain1.com, domain2.com
    virtual_uid_maps = static:2000
    virtual_gid_maps = static:2000
    virtual_mailbox_base = /home/postfix/virtual_mailboxes/
    virtual_mailbox_maps = hash:/etc/postfix/virtual_mailboxes/virtual_mailbox_recipients
    virtual_alias_maps = hash:/etc/postfix/virtual_mailboxes/virtual_mailbox_aliases
    virtual_alias_domains = hash:/etc/postfix/virtual_alias_domains
    

    myhostname is required by postfix and this should be your primary domain.

    Example /etc/postfix/virtual_mailboxes/virtual_mailbox_recipients

    account1@main_domain.com account1/
    account2@domain1.com account2/
    account3@domain2.com account3/
    

    /home/postfix/virtual_mailboxes/{account1,account2,account3} directories must exist.

    You can then add some aliases within /etc/postfix/virtual_mailboxes/virtual_mailbox_aliases

    forward_to_account1@domain1.com account1@main_domain.com
    forward_to_account2@domain1.com account2@domain1.com
    forward_to_account3@domain1.com account3@domain2.com
    forward_to_everybody@domain1.com account1@main_domain.com,account2@domain1.com,account3@domain2.com
    

    You point your virtual mailboxes in your dovecot configuration like this:

    mail_location = maildir:/home/postfix_vuser/virtual_mailboxes/%n
    

    (from dovecot documentation %n - user part in user@domain, same as %u if there's no domain)