Configuring postfix virtual mail domain

Postfix_logo

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
postfixuser:x:1003:1003::/home/postfixuser:/bin/bash

]# cat /etc/group | grep postfixuser
postfixuser:x:1003:

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

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

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:

mydomain_1.com
mydomain_2.com

We should create a file that maps where the mails of each user in each domain will be hosted:
]# vi /etc/postfix/vmaps

user1@mydomain_1.com mydomain_1.com/user1/
user2@mydomain_1.com mydomain_1.com/user2/
user1@mydomain_2.com mydomain_2.com/user1/
user2@mydomain_2.com mydomain_2.com/user2/
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/mydomain_1.com/user1/new
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” user1@mydomain_1.com

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