Install Postfix MTA on Ubuntu 16.04 / 17.10 / 18.04

Postfix is a widely used Mail Transfer Agent (MTA) that most Linux systems use to router email messages… It’s probably the default MTA software on all of Linux distributions… This bref tutorial is going to show students and new users how to install and configure Postfix on Ubuntu 16.04 / 17.10 and 18.04 LTS servers..

In order to set up Postfix to work in a public environmnet, you’ll have to configure Postfix with a qualify domain name pointed to your server… ex. pointing to your Ubuntu servers… Don’t forget to point your MX records to the servers as well.

Once you’re done with the initial setup, continue below to get Postfix installed and configured on Ubuntu.

Step 1: Install Postfix on Ubuntu

To install Postfix on Ubuntu, simple run the commands below…

sudo apt install postfix sasl2-bin

During the installation, you’ll be prompted how you’d like to configure Postfix… for this tutorial, we’ll choose ‘No configuration‘… this will allow us to manually configure Postfix settings to suit yoiur environment… This gives you more control of how Postfix functions in your environements…

Package configuration
  ┌────────────────────────┤ Postfix Configuration ├────────────────────────┐
  │ Please select the mail server configuration type that best meets your     
  │ needs.                                                                    
    No configuration:                                                        
     Should be chosen to leave the current configuration unchanged.          
    Internet site:                                                           
     Mail is sent and received directly using SMTP.                          
    Internet with smarthost:                                                 
     Mail is received directly using SMTP or by running a utility such       
     as fetchmail. Outgoing mail is sent using a smarthost.                  
    Satellite system:                                                        
     All mail is sent to another machine, called a 'smarthost', for          
  │ delivery.                                                                 
    Local only:                                                              

When prompted to choose Postfix configuration, select ‘No configuration‘ option… We’re going to manually configure Postfix…

                    ┌──────┤ Postfix Configuration ├───────┐
                    │ General type of mail configuration:  
                           No configuration               
                           Internet Site                  
                           Internet with smarthost        
                           Satellite system               
                           Local only                     
                           <Ok>              <Cancel>     

After installing continue below to configure…

Step 2: Configure Postfix

Now that Postfix is installed, run the commands below to create its default configuratiion file from the distribution template…

sudo cp /usr/share/postfix/ /etc/postfix/

Now that Postfix configuration file is created… run the commands below to open it…

sudo nano /etc/postfix/

Then use these settings to make it work in most environments…

# Global Postfix configuration file. This file lists only a subset
# of all parameters. For the syntax, and for a complete parameter
# list, see the postconf(5) manual page (command: "man 5 postconf").
# To avoid breaking things, Postfix will use backwards-compatible
# default settings and log where it uses those old backwards-compatible
# default settings, until the system administrator has determined
# if any backwards-compatible default settings need to be made
# permanent in or
# When this review is complete, update the compatibility_level setting
# below as recommended in the RELEASE_NOTES file.
# The level below is what should be used with new (not upgrade) installs.
compatibility_level = 2
# by the mail_owner account (see below).
data_directory = /var/lib/postfix
# The mail_owner parameter specifies the owner of the Postfix queue
# and of most Postfix daemon processes. Specify the name of a user
# particular, don't specify nobody or daemon. PLEASE USE A DEDICATED
mail_owner = postfix
# The myhostname parameter specifies the internet hostname of this
# mail system. The default is to use the fully-qualified domain name
# from gethostname(). $myhostname is used as a default value for many
# other configuration parameters.
myhostname =
#myhostname = virtual.domain.tld
# The mydomain parameter specifies the local internet domain name.
# The default is to use $myhostname minus the first component.
# $mydomain is used as a default value for many other configuration
# parameters.
mydomain =
# Note: you need to stop/start Postfix when this parameter changes.
inet_interfaces = all
#inet_interfaces = $myhostname
#inet_interfaces = $myhostname, localhost
#mydestination = $myhostname, localhost.$mydomain, localhost
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
#mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain,
# mail.$mydomain, www.$mydomain, ftp.$mydomain
# The right-hand side of the lookup tables is conveniently ignored.
# In the left-hand side, specify a bare username, an @domain.tld
# wild-card, or specify a user@domain.tld address.
local_recipient_maps = unix:passwd.byname $alias_maps
#local_recipient_maps = proxy:unix:passwd.byname $alias_maps
#local_recipient_maps =
#mynetworks =,
#mynetworks = $config_directory/mynetworks
#mynetworks = hash:/etc/postfix/network_table
mynetworks =,
# It will take a minute or so before changes become visible. Use
# "postfix reload" to eliminate the delay.
#alias_maps = dbm:/etc/aliases
alias_maps = hash:/etc/aliases
#alias_maps = hash:/etc/aliases, nis:mail.aliases
#alias_maps = netinfo:/aliases
#alias_database = dbm:/etc/aliases
#alias_database = dbm:/etc/mail/aliases
alias_database = hash:/etc/aliases
#alias_database = hash:/etc/aliases, hash:/opt/majordomo/aliases
# The home_mailbox parameter specifies the optional pathname of a
# mailbox file relative to a user's home directory. The default
# mailbox file is /var/spool/mail/user or /var/mail/user. Specify
# "Maildir/" for qmail-style delivery (the / is required).
#home_mailbox = Mailbox
home_mailbox = Maildir/
# sendmail_path: The full pathname of the Postfix sendmail command.
# This is the Sendmail-compatible mail posting interface.
sendmail_path = /usr/sbin/postfix
# newaliases_path: The full pathname of the Postfix newaliases command.
# This is the Sendmail-compatible command to build alias databases.
newaliases_path = /usr/bin/newaliases
# mailq_path: The full pathname of the Postfix mailq command. This
# is the Sendmail-compatible mail queue listing command.
mailq_path = /usr/bin/mailq
# setgid_group: The group for mail submission and queue management
# commands. This must be a group name with a numerical group ID that
# is not shared with other accounts, not even with the Postfix account.
setgid_group = postdrop
#html_directory =
# manpage_directory: The location of the Postfix on-line manual pages.
#manpage_directory =
# sample_directory: The location of the Postfix sample configuration files.
#sample_directory =
#readme_directory =
# add to the end of file: limit an email size to 10M
message_size_limit = 10485760
# limit mailbox size to 1G
mailbox_size_limit = 1073741824

After editing the lines above, save the file….

Next, run the commands below and restart Postfix…..

sudo newaliases
sudo systemctl restart postfix

Postfix is now installed and ready to use…

If you want to use SMTP authentication, you may want to use Dovecot….

Dovecot is an open source IMAP and POP3 email server for Linux/UNIX-like systems, written with security primarily in mind. Dovecot is an excellent choice for both small and large installations. It’s fast, simple to set up, requires no special administration and it uses very little memory.

When using Dovecot… add the hightlighted configuration lines to the end of Postfix file…

# SMTP-Auth settings for Dovecot
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain = $myhostname
smtpd_recipient_restrictions = permit_mynetworks,permit_auth_destination,permit_sasl_authenticated,reject

Then restart Postfix and you’re done…

  • 1 Users Found This Useful
Was this answer helpful?

Related Articles

How to redirect HTTP to HTTPS

If you work with the Apache web server and can change its configuration, follow the Apache...

How to change the ssh port on Linux or Unix server

I am a new Linux/Unix server admin. How do I change the SSH Port for my Linux or Unix server...

How To Install Docker on Ubuntu 18.04 & 16.04 LTS

  Docker is container-based application framework, which wraps a specific application with all...

Install Apache, MariaDB, PHP and PhpMyAdmin in Ubuntu 18.04

Step 1: Install Apache Web Server on Ubuntu 18.04 1. First start by updating your software...

How to install OpenLDAP on Ubuntu 18.04

  LDAP is the Lightweight Directory Access Protocol, which allows for the querying and...