How to Install Postfix MTA on Ubuntu Linux

|

|

The Postfix tutorial instructs Ubuntu 16.04, 17.10, and 18.04 LTS server users on how to install and configure Postfix, the main mail transfer agent utilized by Linux. The server must possess a domain name. Installation involves running specific commands and choosing ‘No configuration’ to manually set up Postfix. Configuration requires a similar process with a…

This article explains how to install Postfix MTA on Ubuntu Linux.

Postfix MTA is a widely used Mail Transfer Agent (MTA) to route email messages on Linux systems. It is the default MTA software on most Linux distributions, including Ubuntu.

Installing Postfix on Ubuntu allows you to set up a reliable and efficient email system that handles incoming and outgoing emails. This can be useful for personal or business use, as well as for web applications that require email functionality.

Additionally, Postfix is highly configurable, which allows you to customize its settings to suit your specific needs and requirements.

To set up Postfix to work in a public environment, you’ll have to configure Postfix with a qualified domain name pointed to your server. For example, mail.example.com is pointing to your Ubuntu servers. Don’t forget to point your MX records to the servers as well.

Install Postfix on Ubuntu

To install Postfix on Ubuntu, 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 configure Postfix settings to suit your environment manually. This gives you more control over how Postfix functions in your environment.

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:                                                              
  │                                                                           
  │                             <Ok>                                                  
  │                                                                         │ 
  └─────────────────────────────────────────────────────────────────────────┘ 

Select the ‘No configuration‘ option when prompted to choose Postfix configuration. We’re going to configure Postfix manually.

                    ┌──────┤ 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.

Configure Postfix

After installing Postfix, run the commands below to create its default configuration file from the distribution template.

sudo cp /usr/share/postfix/main.cf.dist /etc/postfix/main.cf

Now that the Postfix configuration file has been created. Run the commands below to open it.

sudo nano /etc/postfix/main.cf

We 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 main.cf or master.cf.
#
# 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

# QUEUE AND PROCESS OWNERSHIP
#
# The mail_owner parameter specifies the owner of the Postfix queue
# and of most Postfix daemon processes. Specify the name of a user
# account THAT DOES NOT SHARE ITS USER OR GROUP ID WITH OTHER ACCOUNTS
# AND THAT OWNS NO OTHER FILES OR PROCESSES ON THE SYSTEM. In
# particular, don't specify nobody or daemon. PLEASE USE A DEDICATED
# USER.
#
mail_owner = postfix

# INTERNET HOST AND DOMAIN NAMES
#
# 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 = mail.example.com
#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 = example.com

# Note: you need to stop/start Postfix when this parameter changes.
#
inet_interfaces = all
#inet_interfaces = $myhostname
#inet_interfaces = $myhostname, localhost
# See also below, section "REJECTING MAIL FOR UNKNOWN LOCAL USERS".
#
#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 = 168.100.189.0/28, 127.0.0.0/8
#mynetworks = $config_directory/mynetworks
#mynetworks = hash:/etc/postfix/network_table
mynetworks = 127.0.0.0/8, 10.0.0.0/24
# 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
# DELIVERY TO MAILBOX
#
# 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 wish 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 particular administration, and uses little memory.

When using Dovecot, add the highlighted configuration lines to the end of the Postfix main.cf 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.

You may also like the post below:

Like this:



2 responses to “How to Install Postfix MTA on Ubuntu Linux”

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.