Configuring postfix virtual mail domain


This is part of the Postfix documents series, continuation of “Accessing a dovecot imap server using SquirrelMail”. One should complete the initial steps in these docuemtns to make this work.

Create a user to manage postfix
]# useradd postfixuser

Find the GID and UID.

]# cat /etc/passwd | grep postfixuser

]# cat /etc/group | grep postfixuser

In my example the UID and GID of the user postfixuser is 1002.

Edit the main config file.
]# vi /etc/postfix/

Add the below lines:

virtual_mailbox_domains = /etc/postfix/vhosts
virtual_mailbox_base = /home/postfixuser
virtual_mailbox_maps = hash:/etc/postfix/vmaps
virtual_minimum_uid = 1000
virtual_uid_maps = static:1003
virtual_gid_maps = static:1003

List the domains that you wish to host.
]# vi /etc/postfix/vhosts
Add the following lines listing examples of domains:

We should create a file that maps where the mails of each user in each domain will be hosted:
]# vi /etc/postfix/vmaps
Now we need to convert the vmaps text file into a hash file by running the following command:
]# postmap /etc/postfix/vmaps

Restart the postfix server
]# systemctl restart postfix

Now, let us try to test to ensure the virtual domain settings works.
]# ls -l /home/postfixuser/
You may not see any files if you have not sent any mail to user1 in mydomain_1 till now.

From the console of the same server try sending a mail to a user in the virtual domain
]# mail -s “test”

Once the mail is sent you should see files added to user1 folder
ls -l /home/postfixuser/