Friday, January 9, 2009

Linux: Setting up Multi domain Mail server with Postfix and Dovecot

Among the different ways to host virtual domains with Postfix, we'll be looking at the one which supports separate domains and virtual accounts. This server will support mail delivery to multiple domains.

First, mention all domains as virtual hosts.

Change the myhostname line in main.cf :

myhostname = localhost

Then add the following virtual domains to main.cf :

virtual_mailbox_domains = /etc/postfix/vhosts.cfg
virtual_mailbox_base = /var/spool/vmail
virtual_mailbox_maps = hash:/etc/postfix/vmaps.cfg
virtual_uid_maps = static:900
virtual_gid_maps = static:900
virtual_alias_maps = hash:/etc/postfix/valias.cfg

First line states a config file called vhosts.cfg. This config file will contain simple list of all the domains. Like:

mydomain1.com
mydomain2.com
myvirtual.net

Second line states a base directory where mails will be stored.

Third line states a file called vmaps.cfg. This is a two column config file. First column tells a virtual email address. Second column tells a mailbox location. On specifying “/” at the end of the location, it becomes Maildir format. Otherwise, it is mbox format by default.

Then build the hash file using following command:

postmap vmaps.cfg

This creates a file “vmaps.cfg.db”. Postfix reads information in hashes faster than a normal config file.

The contents of vmaps.cfg looks like this:

jay@mydomain1.com mydomain1.com/jay/
jay@mydomain2.com mydomain2.com/jay/
vijay@myvirtual.net virtual.net/vijay/


The absolute path of the virtual mailbox for jay@mydomain1.com is /var/spool/vmail/mydomain1.com/jay/. But, first you should make the directories mydomain1.com and jay. As the mailbox is in maildir format, it needs 3 subdirectories under this mailbox: new, cur, tmp. Just execute following command inside “/var/spool/vmail/mydomain1.com/jay/“

mkdir new cur tmp
chmod 700 new cur tmp

Fourth and Fifth lines define an account to be set up that will posses permissions to access all the mailboxes. The username for this account is ‘virtual’ and it's uid and gid should be “900”.

Sixth line specifies a config file where aliases for virtual accounts can be set.
Add lines like following in this config file:

jay@mydomain1.com jay@indiatimes.co.in

Then execute “postmap valias.cfg” to build a hash file.

At the end, an ownership to the mailboxes should be granted to the ‘virtual’ user. Running this will take care of it:

chown virtual:virtual /var/spool/vmail -Rf

Then execute the command "postfix reload".

In the Next section, we will see how we can configure a Pop3 / Imap server for above virtual domains.

No comments:

Post a Comment