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

Create folders for each domain in the /home/postfixuser folder

]# mkdir /home/postfixuser/mydomain_1.com

]# mkdir /home/postfixuser/mydomain_2.com

For testing let us five the folder permission as chmod 777

]# chmod 777 /home/postfixuser/*

Restart the postfix server
]# systemctl restart postfix

Now let us send a mail to one of the user using a telnet session:

]# telnet localhost 25
Trying ::1…
Connected to localhost.
Escape character is ‘^]’.
220 <My FDQN> ESMTP Postfix
EHLO <My FDQN>
250-<My FDQN>
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
MAIL FROM:root@<My FDQN>
250 2.1.0 Ok
RCPT TO:user2@mydomain_1.com
250 2.1.5 Ok
DATA
354 End data with <CR><LF>.<CR><LF>
Subject:Hello there
This is Shiju
.
250 2.0.0 Ok: queued as 7E68A6D409E2
quit
221 2.0.0 Bye

 

Now check if the files got created in the user’s name

]# ls -l /home/postfixuser/mydomain_1.com/
-rw——- 1 postfixuser postfixuser 565 Sep 14 18:40 user2