Set up a mail server with PostfixAdmin

Postfix Admin is an internet based mostly interface which permits customers to configure and handle a Postfix based mostly e mail server. With Postfix Admin you’ll be able to create and handle a number of digital domains, customers and aliases.

That is the primary publish within the collection for Organising and configuring a mail server which covers creating the mandatory DNS data and explains the way to set up and configure Postfix Admin, Nginx with free Let’s Encrypt certificates, PHP and MySQL.

This tutorial was written for Ubuntu 16.04, nonetheless the identical steps with small modifications ought to work on any newer model of Ubuntu .

Because the conditions to observe this collection, you have to:

  • Ubuntu 16.04 server. The server hostname have to be a FQDN. On this collection we are going to use
  • Consumer with sudo privileges .

DNS settings

You should arrange the next DNS data in your mail system to work:

  • A document, to level your system’s FQDN (hostname) to your mail server IPv4 handle. 3600 IN A
  • MX document, to specify which mail server is accountable for accepting e mail messages on behalf of a recipient’s area. In our case we would like all emails despatched to e mail addresses to be accepted by the mail server.      3600 IN MX  0
  • SPF document, which is used to confirm which mail servers are authorized to ship e mail on behalf of a given area. Within the instance beneath we’re approving the area mail servers (mx) and if the SPF test fails, the consequence can be a smooth failure (~all):      3600 IN TXT "v=spf1 mx ~all"

Reverse DNS (PTR)

Reverse DNS (PTR) is an IP handle to area title mapping, the precise reverse of DNS which maps domains to IP addresses.

Most e mail servers will carry out a reverse DNS lookup on the IP handle that’s making an attempt to hook up with them and will not settle for emails from the server if the PTR document isn’t set.

Most often PTR entries may be set by way of your internet hosting supplier net interface or by contacting the assist crew and ask them to setup an accurate PTR document for you.

You should utilize the dig command to seek out out the reverse DNS of a given IP handle.

$ dig -x
Output: area title pointer

Create a system consumer

Since we’re configuring a mail server with digital customers we’d like one system consumer which would be the proprietor of all mailboxes and can be utilized by the digital customers to entry their e mail messages on the server.

The next command will create a brand new group and consumer named vmail and set the consumer’s house listing to /var/mail/vmail:

$ sudo groupadd -g 5000 vmail
$ sudo useradd -u 5000 -g vmail -s /usr/sbin/nologin -d /var/mail/vmail -m vmail

All digital mailboxes can be saved within the /var/mail/vmail listing.

Set up Nginx PHP and MySQL

Postfix Admin is a PHP based mostly software. To have the ability to entry the PostfixAdmin net interface we have to set up a Internet server and PHP.

Run the next command to put in Nginx, PHP and all required PHP modules:

$ sudo apt set up nginx mysql-server php7.0-fpm php7.0-cli php7.0-imap php7.0-json php7.0-mysql php7.0-opcache php7.0-mbstring php7.0-readline

You’ll be prompted to create a MySQL root password in the course of the set up.

Obtain and Configure Postfix Admin

On the time of the writing, 3.1 is the most recent steady model of Postfix Admin.

Obtain the Postfix Admin archive utilizing the next wget command :

$ wget -q https://downloads.sourceforge.internet/venture/postfixadmin/postfixadmin/postfixadmin-${VERSION}/postfixadmin-${VERSION}.tar.gz

As soon as the obtain is accomplished extract the archive :

$ tar xzf postfixadmin-${VERSION}.tar.gz

Transfer the Postfix Admin supply recordsdata the /var/www listing and create templates_c listing (smarty cache):

$ sudo mv postfixadmin-${VERSION}/ /var/www/postfixadmin
$ rm -f postfixadmin-${VERSION}.tar.gz
$ mkdir /var/www/postfixadmin/templates_c

Each Nginx and PHP-FPM are operating below consumer www-data so we have to change the possession of the /var/www/postfixadmin to that consumer:

$ sudo chown -R www-data: /var/www/postfixadmin

Postfix Admin will use a MySQL database to retailer details about customers, domains and the applying configuration.

Login to the MySQL shell :

$ mysql -u root -p

Create a brand new MySQL consumer and database utilizing the next instructions:

mysql> CREATE DATABASE postfixadmin;
mysql> GRANT ALL ON postfixadmin.* TO 'postfixadmin'@'localhost' IDENTIFIED BY 'P4ssvv0rD';

As an alternative of enhancing the default Postfix Admin configuration we are going to create a brand new file named config.native.php which can overwrite the default software settings:

Open the file together with your textual content file:

$ sudo nano /var/www/postfixadmin/config.native.php

Paste the next php code:

$CONF['configured'] = true;
$CONF['database_type'] = 'mysqli';
$CONF['database_host'] = 'localhost';
$CONF['database_user'] = 'postfixadmin';
$CONF['database_password'] = 'P4ssvv0rD';
$CONF['database_name'] = 'postfixadmin';
$CONF['default_aliases'] = array (
  'abuse'      => '',
  'hostmaster' => '',
  'postmaster' => '',
  'webmaster'  => ''
$CONF['fetchmail'] = 'NO';
$CONF['show_footer_text'] = 'NO';
$CONF['quota'] = 'YES';
$CONF['domain_quota'] = 'YES';
$CONF['quota_multiplier'] = '1024000';
$CONF['used_quotas'] = 'YES';
$CONF['new_quota_table'] = 'YES';
$CONF['aliases'] = '0';
$CONF['mailboxes'] = '0';
$CONF['maxquota'] = '0';
$CONF['domain_quota_default'] = '0';

Save and shut the file.

With the configuration above we’re defining the database kind and the login credentials. Additionally, we’re specifying the default aliases, disabling fetchmail and enabling quota.

Subsequent, run the next command to create the schema for the Postfix Admin database:

$ sudo -u www-data php /var/www/postfixadmin/improve.php

As soon as the database is populated, we are able to go on and create our first PostfixAdmin superadmin consumer utilizing the postfixadmin-cli software.

This consumer can have administration privileges to change any area or software setting.

$ sudo bash /var/www/postfixadmin/scripts/postfixadmin-cli admin add --superadmin 1 --active 1 --password P@$$phrase --password2 P@$$phrase

The output ought to look one thing like this:

Welcome to Postfixadmin-CLI v0.2
The admin has been added!

Set up free Let’s Encrypt SSL Certificates

We’re gonna use the SSL certificates to entry our Postfix Admin set up and allow the Dovecot and Postfix SSL/TLS encryption.

We have now a tutorial about the way to set up a Let’s Encrypt SSL Certificates . An important level right here is to generate a SSL Certificates in your server hostname (FQDN) in our case

When you generated the SSL certificates by following the tutorial linked above, edit your Nginx server block as follows:

    hear 80;
    embody snippets/letsencrypt.conf;
    return 301 https://$host$request_uri;
server {
    hear 443 ssl http2;
    root /var/www;
    ssl_certificate /and so forth/letsencrypt/stay/;
    ssl_certificate_key /and so forth/letsencrypt/stay/;
    ssl_trusted_certificate /and so forth/letsencrypt/stay/;
    embody snippets/ssl.conf;
    embody snippets/letsencrypt.conf;
    location / {
       try_files $uri $uri/ /index.php;
    location /postfixadmin {
       index index.php;
       try_files $uri $uri/ /postfixadmin/index.php;
    location ~* \.php$ {
         fastcgi_split_path_info ^(.+?\.php)(/.*)$;
         if (!-f $document_root$fastcgi_script_name) {return 404;}
         fastcgi_pass  unix:/run/php/php7.0-fpm.sock;
         fastcgi_index index.php;
         embody fastcgi_params;
         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

Reload the Nginx service for adjustments to take impact:

$ sudo systemctl reload nginx

At this level it is best to be capable to login to your Postfix Admin set up at, utilizing the superadmin consumer created earlier on this tutorial.


On this tutorial you might have put in Postfix Admin. Within the subsequent a part of this collection, we are going to proceed with Postfix and Dovecot set up and configuration. 


Submit a Comment

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

Related Articles