How to Install and Configure Postfix on Ubuntu 18.04

Postfix is a free email server originally developed as an alternative, simpler and more secure to sendmail. This article will show you how to setup a postfix mail server on your Ubuntu 18.04 server. Postfix allows you to manage virtual users and for that, we create a virtual group. We will easily manage our mail server using postfixadmin for the virtual users and dovecot for incoming emails.

What you need to understand

To receive mail a prerequisite is to have a fixed IP, a DNS server running either on your own server or to a hosting provider on which you can modify the recordings. Let us define some acronyms which will be used on this configuration:

  • Postfix is the Mail Transfer Agent (MTA) used to send and receive emails
  • Dovecot is the Local Delivery Agent (LDA) which use the Internet Messaging Application Protocol (IMAP) and Post Office Protocol (POP3) server.
  • SASL defined by Simple Authentication and Secure Layer, it adds an authentication between the user and the server to secure exchanges.
  • Postfixadmin the web interface which enables you to manage mailboxes, virtual domains, and aliases
  • LEMP: the web server with Nginx and PHP in order to access postfixadmin and easily manage the virtual users and domains, MySQL to store all the information.

There are two types of domains in Postfix:

  • Local domains used to deliver email to system users which are listed in /etc/passwd file.
  • Virtual domains that do not need system account present in the /etc/passwd file. It provides a way to handle thousands of mail accounts very easily in the mail server system by using MySQL, PostgreSQL, or LDAP for the user account management.

We will configure the second type of domain. You should also read our article on how to install lemp server on Ubuntu 18.04 which is necessary to access the Postfixadmin web interface.

Step 1) Install and configure Postfixadmin

Postfixadmin is a web module that allows you to easily manipulate virtual domains and users in a database.

a) Download postfixadmin

First, we will install the required packages

# apt install php-imap php-mbstring php7.2-imap php7.2-mbstring
Reading package lists... Done
Building dependency tree 
Reading state information... Done
...
...

Normally postfixadmin is present on the default repositories of Ubuntu 18.04 but it will try to install Apache and PostgreSQL instead of Nginx and MySql. So, to keep our configuration, we will download the actual latest version 3.2 from source on the Github site project and save it in /opt folder

# wget -P /opt https://github.com/postfixadmin/postfixadmin/archive/postfixadmin-3.2.tar.gz
--2018-06-11 21:53:14--  https://github.com/postfixadmin/postfixadmin/archive/postfixadmin-3.2.tar.gz
Resolving github.com (github.com)... 192.30.255.113, 192.30.255.112
Connecting to github.com (github.com)|192.30.255.113|:443... connected.
HTTP request sent, awaiting response... 302 Found

Now go to that folder and uncompress it.

# cd /opt && tar xvf postfixadmin-3.2.tar.gz

Now we should rename it

# mv postfixadmin-postfixadmin-3.2/ postfixadmin

Postfixadmin uses a script called setup.php that we will use through the web server during the installation.  On the previous version of postfix (3.1 and oldest), this script is directly in the Postfixadmin root folder but in the actual version (3.2), it's contained in the sub-directory public of the postfixadmin folder. Normally we should move postfixadmin to the root folder of our Nginx web server but with this new version, we will only create a symbolic link of the public folder which contains the script then, rename it for some security

# ln -s /opt/postfixadmin/public/ /var/www/html/pfa
[email protected]:~# ls -l /var/www/html/
total 4
-rw-r--r-- 1 root root 612 Jun 10 04:51 index.nginx-debian.html
lrwxrwxrwx 1 root root  25 Jun 12 04:01 pfa -> /opt/postfixadmin/public/

b) Create the postfix database

Now we should connect to mysql database for some configurations

# mysql -u root -p
Enter password:

Then create the database and the user

mysql> CREATE DATABASE postfix;
Query OK, 1 row affected (0.00 sec)

mysql> CREATE USER 'postfix'@'localhost' IDENTIFIED BY 'postfix-db-password';
Query OK, 0 rows affected (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON `postfix` . * TO 'postfix'@'localhost';
Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye

c) Configure postfixadmin

Now that we have configured the database, we should indicate it to postfixadmin so that it could know where to get the information. To do this, create the /opt/postfixadmin/config.local.php file and add the content below

# vim /opt/postfixadmin/config.local.php

<?php
$CONF['database_type'] = 'mysqli';
$CONF['database_user'] = 'postfix';
$CONF['database_password'] = 'postfix-db-password';
$CONF['database_name'] = 'postfix';

$CONF['configured'] = true;
?>

postfixadmin requires permission to a sub-folder named templates_c that doesn't exist. So to avoid some errors during the installation such as below,

we should need to create it manually and give www-data permission

# mkdir /opt/postfixadmin/templates_c && chmod 755 -R /opt/postfixadmin/templates_c
# chown -R www-data:www-data /opt/postfixadmin/templates_c

Then try again, you will see that it works now and it checks all the configuration, shows the version of your php and Ubuntu

Now we should create a password for the setup and generate its hash

Now it will allow you to create the superadmin account and you will use the setup password that you have created. But for this, you need to edit the /opt/postfixadmin/config.local.php file in order to add the value of the generated password hash. Then proceed to the superadmin account creation

Now you will see that the account has been added.

Now as you can see, you can login to postfixadmin with the account using the link http://your-ip-or-domain/pfa

If this page can not appear, please check the nginx error log file

# tail -n 20 -f /var/log/nginx/error.log

And make sure to have the right permissions on the /opt/postfixadmin/templates_c folder. You can see the description of each menu when you log in.

d) Create virtual domains, users, and alias

Now we will create the virtuals domains, then the users. A domain is a domain name such as mytuto.com. You can have emails on your domain using the same server. When you start you don't have any domain. To add a domain, go to Domains List -> New Domain.

Then enter the information about the domain. You can limit the number of aliases and mailboxes. Remember to add the MX record.  When finish to choose your values, add the domain.

Now that our virtual domain is created, you can see in the Domain list

We can now create our virtual users. To do this, go to Virtual List -> Add mailbox.

We can also create aliases. These are email addresses that will redirect the mails to another account. Normally any mail server must have an email address abuse, so that we can for example report a spam from a domain. So just create an alias abuse from your domain to your user you just created earlier. To do this, go to Virtual List -> Add Alias.

You can create all those virtual parameters at the end but it will help us in the next step for the configuration of postfix.

Step 2) Install and configure postfix

a) Install postfix

Now we can install the postfix packages.

# apt install postfix postfix-mysql sasl2-bin
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  db-util db5.3-util libmysqlclient20 ssl-cert
Suggested packages:
  procmail postfix-pgsql postfix-ldap postfix-pcre postfix-lmdb
...
...

You will have to answer two question about the type of mail and the name of your mail server. Make sure to replace the hostname and domain values with yours

  • the type of mail configuration: Internet Site
  • the system mail name: hostname.domain.com

Make sure that sasl run at the startup by editing its configuration file

# vim /etc/default/saslauthd

# Should saslauthd run automatically on startup? (default: no)
START=yes

Now restart the service

# systemctl restart saslauthd

As we are configuring a mail server with virtual users, we need an owner of all mailboxes so will create a system user which will be used by all virtual users to access email on the server. First, create the group owner and the folder which will store the mailboxes.

# groupadd -g 5000 vmail && mkdir -p /var/mail/vmail

Now create the owner

# useradd -u 5000 vmail -g vmail -s /usr/sbin/nologin -d /var/mail/vmail

Make sure to give the permission of the mail directory to the owner so that it can store the mails into the appropriate directories.

# chown -R vmail:vmail /var/mail/vmail

If you don't do this, dovecot will not be able to create the required folders to store the emails.

b) Create the configuration files for the database

Now create a folder which will contain some database files

# mkdir -p /etc/postfix/sql

Postfix need 03 database files which will allow it to access the database that we created earlier:

  • Domains to contain the list of domain names hosted on the server. it will allow postfix to determine if our server is in charge of a domain (mytuto.com) when it receives an email ([email protected]) on it. If it's the case, it will mean that the domain is in our database.
# vim /etc/postfix/sql/mysql_virtual_domains_maps.cf
user = postfix
password = postfix-db-password
hosts = 127.0.0.1
dbname = postfix
query = SELECT domain FROM domain WHERE domain='%s' AND active = '1'

We will enable the configuration and add it automatically to the /etc/postfix/main.cf file and reload the postfix configuration to avoid having to do it manually. So the file will be updated everytime you use this command with new values.

# postconf -e virtual_mailbox_domains=mysql:/etc/postfix/sql/mysql_virtual_domains_maps.cf

Now we can check the configuration. We will run a command that will execute the query contained in the file in order to search for a domain in our database. An element (the searched domain) must be returned or nothing if the domain is not present.

# postmap -q mytuto.com mysql:/etc/postfix/sql/mysql_virtual_domains_maps.cf
mytuto.com

As you can see, postfix is able to retrieve the domains stored in our database

  • Mailbox to store all the virtual email addresses. It will be used to verify also if the mailboxes exist
# vim /etc/postfix/sql/mysql_virtual_mailbox_maps.cf
user = postfix
password = postfix-db-password
hosts = 127.0.0.1
dbname = postfix
query = SELECT maildir FROM mailbox WHERE username='%s' AND active = '1'

Now let's update the configuration file

# postconf -e virtual_mailbox_maps=mysql:/etc/postfix/sql/mysql_virtual_mailbox_maps.cf

Run the command to test the query on the database

# postmap -q [email protected] mysql:/etc/postfix/sql/mysql_virtual_mailbox_maps.cf
mytuto.com/alain/
  • Alias to contain the different email aliases.
# vim /etc/postfix/sql/mysql_virtual_alias_maps.cf
user = postfix
password = postfix-db-password
hosts = 127.0.0.1
dbname = postfix
query = SELECT goto FROM alias WHERE address='%s' AND active = '1'

Now add the configuration

# postconf -e virtual_alias_maps=mysql:/etc/postfix/sql/mysql_virtual_alias_maps.cf

Now run the command to test the query. It is the destination user ([email protected]) that should be displayed and not the abuse address. It shows that postfix can do the matching.

# postmap -q [email protected] mysql:/etc/postfix/sql/mysql_virtual_alias_maps.cf
[email protected]

Make sure that those files are not readable by the normal users because the passwords are stored in clear.

# ls -l /etc/postfix/sql/
total 12
-rw-r--r-- 1 root root 138 Jun 13 06:53 mysql_virtual_alias_maps.cf
-rw-r--r-- 1 root root 140 Jun 13 05:18 mysql_virtual_domains_maps.cf
-rw-r--r-- 1 root root 144 Jun 13 07:04 mysql_virtual_mailbox_maps.cf

In order for postfix to read those file, we can change the group owner to postfix

# chgrp postfix /etc/postfix/sql/mysql_*.cf
# ls -l /etc/postfix/sql/
total 12
-rw-r--r-- 1 root postfix 138 Jun 13 06:53 mysql_virtual_alias_maps.cf
-rw-r--r-- 1 root postfix 140 Jun 13 05:18 mysql_virtual_domains_maps.cf
-rw-r--r-- 1 root postfix 144 Jun 13 07:04 mysql_virtual_mailbox_maps.cf

c) Configure postfix

Now we will manually edit the postfix main configuration file. So, make a copy before editing

# cp /etc/postfix/main.cf /etc/postfix/main.cf.bak

Now we will activate SASL to force authentication for sending emails and hand off authentication to Dovecot. Be sure to add lines below

# vim /etc/postfix/main.cf

# Allow authenticated users to send email, and use Dovecot to authenticate them. Tells Postfix to use Dovecot for authentication
smtpd_sasl_type = dovecot
## Path to the Postfix auth socket
smtpd_sasl_path = private/auth
## Tells Postfix to let people send email if they've authenticated to the server.
## Otherwise they can only send if they're logged in (SSH)
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain = $myhostname
# Enable authentication only for those with a TLS connection.
smtpd_tls_security_level = may
smtpd_tls_auth_only = no
# Tells Postfix who can send email: SASL-authenticated users connecting from a network specified in 'mynetworks'
smtpd_recipient_restrictions = permit_mynetworks permit_sasl_authenticated reject_unauth_destination

Now let's edit the /etc/postfix/master.cf configuration file. It's the process configuration file. We will enable secure SMTP ports by adding or uncomment the lines below and make a copy before

# cp /etc/postfix/master.cf /etc/postfix/master.cf.bak
# vim /etc/postfix/master.cf
submission inet n       -       y       -       -       smtpd
  -o syslog_name=postfix/submission
  -o smtpd_tls_security_level=encrypt
  -o smtpd_sasl_auth_enable=yes
#  -o smtpd_tls_auth_only=yes
#  -o smtpd_reject_unlisted_recipient=no
#  -o smtpd_client_restrictions=$mua_client_restrictions
  -o smtpd_client_restrictions=permit_sasl_authenticated,reject
#  -o smtpd_helo_restrictions=$mua_helo_restrictions
#  -o smtpd_sender_restrictions=$mua_sender_restrictions
#  -o smtpd_recipient_restrictions=
#  -o smtpd_relay_restrictions=permit_sasl_authenticated,reject
  -o milter_macro_daemon_name=ORIGINATING
smtps     inet  n       -       y       -       -       smtpd
  -o syslog_name=postfix/smtps
  -o smtpd_tls_wrappermode=yes
  -o smtpd_sasl_auth_enable=yes
#  -o smtpd_reject_unlisted_recipient=no
#  -o smtpd_client_restrictions=$mua_client_restrictions
#  -o smtpd_helo_restrictions=$mua_helo_restrictions
#  -o smtpd_sender_restrictions=$mua_sender_restrictions
#  -o smtpd_recipient_restrictions=
#  -o smtpd_relay_restrictions=permit_sasl_authenticated,reject
  -o smtpd_client_restrictions=permit_sasl_authenticated,reject
  -o milter_macro_daemon_name=ORIGINATING

Now you can run the postconf -n command to check some errors

# postconf -n
alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
...
...

If you have no warning messages, it means that your files do not contain errors. Now you can restart the postfix service

# systemctl restart postfix
# systemctl status postfix
● postfix.service - Postfix Mail Transport Agent
   Loaded: loaded (/lib/systemd/system/postfix.service; enabled; vendor preset: enabled)
   Active: active (exited) since Wed 2018-06-13 10:16:02 UTC; 27s ago
  Process: 12225 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
 Main PID: 12225 (code=exited, status=0/SUCCESS)

Step 3) Install and configure Dovecot

Now that Postfix is installed and configured, we need to install postfix to manage the pop and imap protocols, which allow us to recover our emails.

a) Installation of Dovecot

Dovecot packages are presents in the Ubuntu 18.04 default repositories. We will install it with the mysql support. We will install sieve which is useful because it will automatically put the mails into the corresponding folders. It means that, for each domain, it will create a corresponding folder containing the corresponding folder of a virtual user to store its email files.

# apt install dovecot-imapd dovecot-mysql dovecot-managesieved
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  dovecot-core dovecot-sieve libexttextcat-2.0-0 libexttextcat-data
Suggested packages:
...
...

Understand that, if you don't want to use sieve, for each domain, you will probably need to manually create the corresponding folders in order to store its emails and this not easy if you have many domains.

b) Configuration of dovecot

The configuration of Dovecot is contained into multiples files in /etc/dovecot/conf.d. First, check the content of the /etc/dovecot/dovecot.conf to have these lines uncommented

!include_try /usr/share/dovecot/protocols.d/*.protocol
!include conf.d/*.conf

Now go to the folder containing the configuration files

# cd /etc/dovecot/conf.d

We will edit:

  • the 10-auth.conf file to modify the connection mechanisms by adding or uncommenting the lines. Dovecot uses the system users by default but we use Mysql users
# cp 10-auth.conf 10-auth.conf.bak
# vim 10-auth.conf

auth_mechanisms = plain login
#!include auth-system.conf.ext
!include auth-sql.conf.ext
  • the auth-sql.conf.ext file for the sql configuration
# cp auth-sql.conf.ext auth-sql.conf.ext.bak
# vim auth-sql.conf.ext

passdb {
  driver = sql
  args = /etc/dovecot/dovecot-sql.conf.ext
}

userdb {
  driver = static
  args = uid=vmail gid=vmail home=/var/mail/vmail/%d/%n
}
  • now let's edit the /etc/dovecot/dovecot-sql.conf.ext to tell dovecot how to connect to the SQL database
# cp /etc/dovecot/dovecot-sql.conf.ext /etc/dovecot/dovecot-sql.conf.ext.bak
# vim /etc/dovecot/dovecot-sql.conf.ext

driver = mysql
connect = host=127.0.0.1 dbname=postfix user=postfix password=postfix-db-password
password_query = SELECT username,domain,password FROM mailbox WHERE username='%u';
default_pass_scheme = MD5-CRYPT
  • Now we will edit the 10-mail.conf file to configure the mail location directory
# cp 10-mail.conf 10-mail.conf.bak
# vim 10-mail.conf
mail_location = maildir:/var/mail/vmail/%d/%n/Maildir
mail_privileged_group = mail
  • Now we will edit the 10-master.conf file for the connection to the socket.
# cp 10-master.conf 10-master.conf.bak
# vim 10-master.conf

service auth {
  unix_listener auth-userdb {
    mode = 0600
    user = vmail
  }

  unix_listener /var/spool/postfix/private/auth {
    mode = 0660
    user = postfix
    group = postfix
  }

  user = dovecot
}
  • Now we need to configure the LDA 15-lda.conf file to indicate sieve in order to automatically organize mail into the corresponding folder
# cp 15-lda.conf 15-lda.conf.bak
# vim 15-lda.conf

protocol lda {
  # Space separated list of plugins to load (default is global mail_plugins).
  mail_plugins = $mail_plugins sieve
}

We should give permission if we want that the vmail user can launch dovecot

# chgrp vmail /etc/dovecot/dovecot.conf

Now you can restart the dovecot service

# systemctl restart dovecot

You can check the mail log for any error

# tail -n 20 -f /var/log/mail.log

c) Integrate dovecot to postfix

Now that we have configured dovecot, we should indicate postfix to work with dovecot. Edit the master postfix configuration file and add the lines below at the end of the file

# vim /etc/postfix/master.cf

dovecot   unix  -       n       n       -       -       pipe
  flags=DRhu user=vmail:vmail argv=/usr/lib/dovecot/deliver -f ${sender} -d ${user}@${nexthop}

Now edit the main postfix configuration file

 # vim /etc/postfix/main.cf
virtual_transport = dovecot
dovecot_destination_recipient_limit = 1

Then restart postfix

# systemctl restart postfix

You can check the mail log for any error

# tail -n 20 -f /var/log/mail.log
Jun 14 08:10:00 myserver postfix/postfix-script[28361]: starting the Postfix mail system
Jun 14 08:10:00 myserver postfix/master[28363]: daemon started -- version 3.3.0, configuration /etc/postfix

You can see that all the configuration is good. now we need to do some test

Step 4) Test of mail server

For the tests in command line, we need to install the mailutils package before sending email

# apt install mailutils
Reading package lists... Done
Building dependency tree 
Reading state information... Done
The following additional packages will be installed:
 guile-2.0-libs libgc1c2 libgsasl7 libkyotocabinet16v5 libltdl7 libmailutils5 libntlm0 libpython2.7 libpython2.7-minimal libpython2.7-stdlib
 mailutils-common
...
...

Now we need to send some email and check if the folders corresponding to the domains and users are effectively created. For that, we will first send a mail to our current user created in postfixadmin during its configuration

# echo "Hello Alain" | mail -s "test mail" [email protected]

First, let's check the mail log

 # tail -n 20 -f /var/log/mail.log

Jun 14 08:17:04 myserver postfix/qmgr[28374]: 1715240BF9: from=<[email protected]>, size=384, nrcpt=1 (queue active)
Jun 14 08:17:04 myserver dovecot: lda([email protected]): msgid=<[email protected]>: saved mail to INBOX
Jun 14 08:17:04 myserver postfix/pipe[28406]: 1715240BF9: to=<[email protected]>, relay=dovecot, delay=0.05, delays=0.02/0.01/0/0.03, dsn=2.0.0, status=sent (delivered via dovecot service)
Jun 14 08:17:04 myserver postfix/qmgr[28374]: 1715240BF9: removed

We can see that the mail has been sent with success. Now let's check if the corresponding folders have been created

# ls -R /var/mail/vmail/
/var/mail/vmail/:
mytuto.com

/var/mail/vmail/mytuto.com:
alain

/var/mail/vmail/mytuto.com/alain:
Maildir

/var/mail/vmail/mytuto.com/alain/Maildir:
cur  dovecot.index.cache  dovecot.index.log  dovecot-uidlist  dovecot-uidvalidity  dovecot-uidvalidity.5b222480  new  tmp

/var/mail/vmail/mytuto.com/alain/Maildir/cur:

/var/mail/vmail/mytuto.com/alain/Maildir/new:
'1528964224.M129536P28407.myserver,S=455,W=467'

/var/mail/vmail/mytuto.com/alain/Maildir/tmp:

You can see that the folders are automatically presents. For a better view, let us try with the command tree. First install it

 apt install tree

Now let's see the mail folders with a better view

# tree /var/mail/vmail/
/var/mail/vmail/
└── mytuto.com
    └── alain
        └── Maildir
            ├── cur
            ├── dovecot.index.cache
            ├── dovecot.index.log
            ├── dovecot-uidlist
            ├── dovecot-uidvalidity
            ├── dovecot-uidvalidity.5b222480
            ├── new
            │   └── 1528964224.M129536P28407.myserver,S=455,W=467
            └── tmp

6 directories, 6 files

Now you can perfectly see. We can do another test by creating a new virtual domain and user on postfixadmin. Let's create the virtual domain example.com

and the virtual user [email protected]

Now let's send a mail to the new virtual user

# echo "Hello Francois" | mail -s "test config" [email protected]

Now check the mail log

# tail -n 20 -f /var/log/mail.log

Jun 14 08:35:10 myserver postfix/qmgr[28374]: CE43F40C5E: from=<[email protected]>, size=393, nrcpt=1 (queue active)
Jun 14 08:35:10 myserver dovecot: lda([email protected]): msgid=<[email protected]>: saved mail to INBOX
Jun 14 08:35:10 myserver postfix/pipe[28481]: CE43F40C5E: to=<[email protected]>, relay=dovecot, delay=0.06, delays=0.02/0.01/0/0.03, dsn=2.0.0, status=sent (delivered via dovecot service)
Jun 14 08:35:10 myserver postfix/qmgr[28374]: CE43F40C5E: removed

Now verify the folder tree

# tree /var/mail/vmail/
/var/mail/vmail/
├── example.com
│   └── francois
│       └── Maildir
│           ├── cur
│           ├── dovecot.index.cache
│           ├── dovecot.index.log
│           ├── dovecot-uidlist
│           ├── dovecot-uidvalidity
│           ├── dovecot-uidvalidity.5b2228be
│           ├── new
│           │   └── 1528965310.M888145P28482.myserver,S=468,W=480
│           └── tmp
└── mytuto.com
    └── alain
        └── Maildir
            ├── cur
            ├── dovecot.index.cache
            ├── dovecot.index.log
            ├── dovecot-uidlist
            ├── dovecot-uidvalidity
            ├── dovecot-uidvalidity.5b222480
            ├── new
            │   └── 1528964224.M129536P28407.myserver,S=455,W=467
            └── tmp

You can see that we have two sub-directories with the domains mytuto.com and example.com which the file for each virtual user of the different domains. Now let's do the last test, the virtuals users will be exchanging emails

# echo "Hello Francois, it's Alain" | mail -s "Subject" -aFrom:alain\<[email protected]\> [email protected]

Check the mail log

# tail -n 20 -f /var/log/mail.log

Jun 14 23:15:01 myserver postfix/pickup[28373]: 8558240BDA: uid=0 from=<[email protected]>
Jun 14 23:15:01 myserver postfix/cleanup[28595]: 8558240BDA: message-id=<[email protected]>
Jun 14 23:15:01 myserver postfix/qmgr[28374]: 8558240BDA: from=<[email protected]>, size=398, nrcpt=1 (queue active)
Jun 14 23:15:01 myserver dovecot: lda([email protected]): msgid=<[email protected]>: saved mail to INBOX
Jun 14 23:15:01 myserver postfix/pipe[28597]: 8558240BDA: to=<[email protected]>, relay=dovecot, delay=0.05, delays=0.02/0.01/0/0.03, dsn=2.0.0, status=sent (delivered via dovecot service)
Jun 14 23:15:01 myserver postfix/qmgr[28374]: 8558240BDA: removed

We can now see the mail folder

# tree /var/mail/vmail/
/var/mail/vmail/
├── example.com
│   └── francois
│       └── Maildir
│           ├── cur
│           ├── dovecot.index.cache
│           ├── dovecot.index.log
│           ├── dovecot-uidlist
│           ├── dovecot-uidvalidity
│           ├── dovecot-uidvalidity.5b2228be
│           ├── new
│           │   ├── 1528965310.M888145P28482.myserver,S=468,W=480
│           │   └── 1528966081.M582572P28598.myserver,S=455,W=467
...
...

you can see that the folder new contains now two files. We can open the file containing the mail

# cat /var/mail/vmail/example.com/francois/Maildir/new/1528966081.M582572P28598.hostname\,S\=455\,W\=467 
Return-Path: <[email protected]>
Delivered-To: [email protected]
Received: by myserver.domain.com (Postfix, from userid 0)
        id 8558240BDA; Thu, 14 Jun 2018 23:15:01 +0000 (UTC)
Subject: Subject
From: alain<[email protected]>
To: <[email protected]>
X-Mailer: mail (GNU Mailutils 3.4)
Message-Id: <[email protected]>
Date: Thu, 14 Jun 2018 23:15:01 +0000 (UTC)

Hello Francois, it's Alain

You can see the content which shows that it also works.

Conclusion

You know how to configure a fully functional mail system with Postfix, Dovecot and Postfixadmin with Nginx. The most important is to give the right permission to don't face issues. You should notice that you can use dovecot with others protocols instead of LDA. Next time we will show you how to install RoundCube so that the virtuals users can have a web interface to easily read their emails and we will integrate PhpMyAdmin to easily manipulate the database. Feel free to send us your comments to improve this tutorial.

Read also

Alain Francois 7:29 am

About Alain Francois

IT Linux administrator passionate of free and open source software, I work on Linux Systems since some years on installations and deployments of certain solutions. I like to share my experiences with a wider audience by training and conferences.

Author Archive Page

Have anything to say?

Your email address will not be published. Required fields are marked *

All comments are subject to moderation.

2 Comments

  1. Hello, great and usefull guide.

    I issued one problem, but solved
    When I tested sending email I got permissions error, and found that in 10-mail.conf this need to be commented: mail_location = mbox:~/mail:INBOX=/var/mail/%u
    Maybe you can say that in your section for this file.

    Also suggestion about this image
    https://linoxide.com/wp-content/uploads/2018/06/13-postfix-dovecot-pfa-test1.png
    These check boxes can confused someone who setting this for the first time. Because this option is for backup mail server, and we are setting here main mail server.

    And to complete guide, I would suggest if you find time to show us:
    - How to protect our server to be spam blacklisted, and setup mail server and domain to have 10/10 evaluation on mail-tester (including SPF, DKIM and PTR)
    - How to protect server from spam, including spamassassin, setting DNSBL...
    - How to setup backup-restore procedure from one to another server if something goes wrong with main server.

    Thank you

    1. Hello CoyoteKG,

      Effectively, you need to comment or edit the mail location present in the 10-mail.conf file while adding the one in the tutorial.

      thank you for your suggestion.