Multiple Domains and Virtual Mailboxes on Postfix

Moderators: ashishsinha, alok, Linux Moderators

Multiple Domains and Virtual Mailboxes on Postfix

Postby alok on Tue Aug 23, 2011 3:54 pm

I want:

1. Multiple domains on Postfix.
2. Want separate mailboxes for each domain.
3. Don't want to create system user accounts for email users as they will never login and they will just be the "email users".


To achieve these three objective is actually a THREE step process.

PS: The prerequisite is that your basic postfix should be live and kicking alongwith the DNS with the respective zones.

STEP #1. Define how many domains you want. In my case I need two virtual domains abc.com and xyz.com. So edit vim /etc/postfix/main.cf, and add this line

Code: Select all
virtual_mailbox_domains = abc.com, xyz.com


OR if you have too many domains you can also use this option in /etc/postfix/main.cf

Code: Select all
virtual_mailbox_domains = /etc/postfix/virtual_domains


Then create a file /etc/postfix/virtual_domains, with these lines

Code: Select all
abc.com
xyz.com
king.com
.
.
.


STEP #2. Define and plan some structure for the virtual mailboxes. In my case I need separate directories (or locations) for each domain so that there should not be any problem and in case of same email name, the email should be delivered to the right mailbox. So I will be creating two directories for my domains.

Code: Select all
mkdir /var/spool/mail/abc.com
mkdir /var/spool/mail/xyz.com


Change the permissions

Code: Select all
chmod 777 /var/spool/mail/abc.com
chmod 777 /var/spool/mail/xyz.com


Now tell the postfix to use this mailbox base. Edit the /etc/postfix/main.cf file and add this line -

Code: Select all
virtual_mailbox_base = /var/spool/mail


Now create the lookup file that maps the email address to their mailboxes. For this edit /etc/postfix/main.cf and add this line -

Code: Select all
virtual_mailbox_maps = hash:/etc/postfix/virtual


After you save and exit run -

Code: Select all
postmap /etc/postmap/virtual


to make your changes applied.

Now edit the /etc/postfix/virtual file -- and add these lines

Code: Select all
info@abc.com    abc.com/info
info@xyz.com    xyz.com/info


PS: By this I had made sure that email send to info@abc.com will be going under /var/spool/mail/abc.com/info and email send to info@xyz.com will be going under /var/spool/mail/xyz.com/info

STEP #3. Now a$$ign mailboxes owner$hip.

- The virtual mailboxes files must be owned by a user account and a group on the system.
- Create a user account (say vmail) and a group (say vmail) using the useradd command and note down their uid and gid values.

In this example my:
vmail user account uid = 1003
vmail group account gid = 1003

Now edit the /etc/postfix/main.cf and add these lines -

Code: Select all
virtual_uid_maps = static:1003
virtual_uid_maps = static:1003


Save and exit. Restart your postfix and dovecot services.

Code: Select all
service postfix restart; chkconfig postfix on
service dovecot restart; chkconfig dovecot on


So after this - if you send the email to "info@abc.com" it will be going in /var/spool/mail/abc.com/info
and if you send the email to "info@xyz.com" it will be going in /var/spool/mail/xyz.com/info


without even creating any user account on the system... .and you are managing two virtual domains.

Enjoy your Edge !!! :twisted:
User avatar
alok
 
Posts: 237
Joined: Tue Dec 23, 2008 11:11 am

Return to Linux Room

Who is online

Users browsing this forum: No registered users and 2 guests