Learn How to Setup Email Services using Postfix in Linux


There are a number of reasons why you would want to set up your own Linux mail server. These days more people than ever are compelled to get their email fixed – if it ever fails. Postfix is an MTA (Mail switch Agent), a software used to send and receive mail. It is Wietse Venema’s mail server that began life at IBM research alternatively to the largely used Sendmail application. Now at Google, Wietse continues to support Postfix. This article explains about – How to setup Email Services using postfix in Linux.

To install Postfix and test mail utilities, use the following command –

$ sudo apt-get install mailutils

The sample output should be like this-

Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
   linux-headers-4.4.0-53 linux-headers-4.4.0-53-generic
   linux-image-4.4.0-53-generic linux-image-extra-4.4.0-53-generic
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
   libgsasl7 libkyotocabinet16v5 libmailutils4 libntlm0 mailutils-common
Suggested packages:
   mailutils-mh mailutils-doc procmail postfix-mysql postfix-pgsql postfix-ldap
   postfix-pcre sasl2-bin dovecot-common postfix-cdb postfix-doc
The following NEW packages will be installed:
   libgsasl7 libkyotocabinet16v5 libmailutils4 libntlm0 mailutils
   mailutils-common postfix

While installation process is going on, it will promote the following screen to configure postfix-

Click on ok button to move ahead. Now it will promote the following screen to configure general type of mail configuration as shown below –

Select internet site and click on Ok button. By default, it takes the system name as system mail name as shown in the below screen –

Change the system mail name according to the requirement. For instance, we have taken as tutorialspoint.com as system mail name. Now click on ok button. After completing the installation process, you are required to configure postfix. To do that, open the configure file using the following command.

$sudo nano /etc/postfix/main.cf

The sample output should be like this –

# See /usr/share/postfix/main.cf.dist for a commented, more complete version

# Debian specific: Specifying a file name will cause the first
# line of that file to be used as the name. The Debian default
# is /etc/mailname.
#myorigin = /etc/mailname

smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no

# appending .domain is the MUA's job.
append_dot_mydomain = no

# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h

readme_directory = no

Now look up for inet_interfaces = all and rechange it as inet_interfaces = loopback-only.The sample output should be like this –

mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = loopback-only
inet_protocols = all

Save the file by clicking Ctrl+O and close the file by clicking Ctrl+X.Now restart Postfix using the following command –

$ sudo service postfix restart

To get the more information about postfix, use the following command –

$ man postfix

The sample output should be like this –

POSTFIX(1)                   General Commands Manual                      POSTFIX(1)

      postfix - Postfix control program
      postfix [-Dv] [-c config_dir] command
   This command is reserved for the superuser. To submit mail, use the
   Postfix sendmail(1) command.

   The postfix(1) command controls the operation of the Postfix mail sys‐
   tem: start or stop the master(8) daemon, do a health check, and other

   By default, the postfix(1) command sets up a standardized environment
   and runs the postfix-script shell script to do the actual work.

   However, when support for multiple Postfix instances is configured,
   postfix(1) executes the command specified with the multi_instance_wrap‐
   per configuration parameter. This command will execute the command for
   each applicable Postfix instance.

Using the following command to send the mail using Postfix as shown blow –

echo "Tutorials Point originated from the idea that there exists a class of readers who respond better 
to online content and prefer to learn new skills at their own pace from the comforts of their drawing 
rooms." | mail -s "About us" sairamkrishna@tutorialspoint.com

Now check your inbox or spam folder to verify mail.The sample output of above mail should be like this –

In the above article, we have learnt about – Learn how to setup Email Services using postfix in Linux. In our next articles, we will come up with more Linux based tricks and tips. Keep reading!

Published on 21-Jan-2020 10:31:12