How to add e-mail accounts to Postfix on Ubuntu Server 20.04

Louis SanchezAugust 14th 2021, 4:00

Follow these steps to add e-mail account:

Step 1 : Create a new user account:

sudo useradd -s /usr/sbin/nologin -m usermail

Step 2 : Get the UID and GID for this account

sudo grep usermail /etc/passwd

Step 3 : Create a base directory layout for domains and users

sudo mkdir -p /home/usermail/
sudo mkdir -p /home/usermail/

Step 4 : Allow only the user usermail to access these files:

sudo chown -R usermail:usermail /home/usermail
chmod -R 700 /home/usermail

Step 5 : Next, configure Postfix. Edit /etc/postfix/ and add the following lines:

virtual_mailbox_base = /home/usermail
virtual_mailbox_domains = /etc/postfix/virtual_domains
virtual_mailbox_maps = hash:/etc/postfix/virtual_maps
virtual_alias_maps = hash:/etc/postfix/virtual_alias
virtual_uid_maps = static:1000  # user ID for user usermail
virtual_gid_maps = static:1000  # group ID for user usermail

Step 6 : Create the file virtual_domains under /etc/postfix

sudo nano /etc/postfix/virtual_domains

Step 7 : Create the virtual_maps file

sudo nano /etc/postfix/virtual_maps   # catch all address

Step 8 : Create the virtual_alias file and optionally set a redirect

sudo nano /etc/postfix/virtual_alias
# redirect emails for tim to bob

Step 9 : Now generate database of virtual maps and aliases by hashing respective files:

sudo postmap /etc/postfix/virtual_maps
sudo postmap /etc/postfix/virtual_alias

Step 10 : Reload Postfix

sudo postfix reload

Step 11 : send an e-mail to the newly created address: