How to Setup Postfix as a Send-only Mail Server | HostAdvice

How to Setup Postfix as Send-only Mail Server on an Ubuntu 18.04 Dedicated Server or VPS

Postfix is a widely used open source Mail Transfer Agent (MTA) for routing and delivering mails on the internet. The SMTP (Simple Mail Transfer Protocol) server started life in 1997 and was originally written by Wietse Venema.

If you would like to get crucial emails from your Ubuntu 18.04 server (e.g. from cron jobs, automated backups completion, e.t.c) you can install Postfix as a send-only mail server.

Postfix is easy to administer, fast and resource efficient. The email server is also security focused and has an active development team. According to a recent report by Security Space, Postfix controls 33% of all emails sent on the web as of June 2018.

In this guide, we focus on the steps needed to completely setup Postfix on your Ubuntu 18.04 to ensure that you don’t miss those crucial emails from your system.

Prerequisites

  • A domain name
  • An Ubuntu 18.04 server
  • A non-root user with sudo privileges

Step 1: Point your server to a Fully Qualified Domain Name (FQDN)

The first thing is to make sure that your server hostname is set to a Fully Qualified Domain Name.(FQDN).

A FQDN is a unique address that identifies your server on the internet and consists of two parts; a hostname(e.g. mail or pluto or nyc ) and a domain name(e.g. example.com).

So the basic syntax of a FQDN should be:

$ [host name].[domain].[tld].

Example

mail.example.com

To setup a FQDN on your Ubuntu 18.04 server, first, edit the /etc/hostname file and change the name to ‘mail’. You can use any other name depending on your needs and most people use names of planets, cities e.t.c

$ sudo nano /etc/hostname

‘/etc/hostname’ File excerpt

mail

Press CTRL +X, Y and Enter to save the changes on that file.

To enter the  domain name part and create a FQDN, we will need to open the ‘etc/hosts’ file:

$ sudo nano /etc/hosts

Set the values below at the top of the file. Remember to replace ‘example.com’ and ‘198.51.100.3’ with your domain name and server public IP address respectively.

127.0.0.1       localhost
127.0.1.1       mail.example.com mail
198.51.100.3    mail.example.com mail

Step 2: Install Postfix

Update the package information by running the command below:

$ sudo apt-get update

To install Postfix with all associated utilities for testing out the email, run the command below:

$ sudo apt-get install mailutils

Before the installation is completed, you will be presented with an option to customize postfix.

On the General type of email configuration, choose ‘Internet Site’. Press, TAB to highlight ‘OK’ and then press Enter.

On the ‘System mail name’ field, enter your domain name (e.g. example.com NOT ‘mail.example.com’)

Press TAB again and Enter to proceed. Your postfix installation will now be completed successfully.

Step 3: Configure Postfix

Most Postfix configuration settings are found on the /etc/postfix/main.cf file. We will do one major change on this file to ensure that Postfix can only send emails coming from our local server to avoid it from being used as an open relay by spammers.

To do this open the configuration file using a nano editor:

$ sudo nano /etc/postfix/main.cf

Look for the entry ‘inet_interface’ and change its value from ‘all’ to ‘loopback-only’

inet_interfaces = loopback-only

Also, check the entry ‘myhostname’ and change its value to the fully qualified domain name of your server

myhostname=mail.example.com

Press CTRL + X, Y and Enter to save the changes

Step 4: Restart Postfix

Once you make the changes, you need to reload Postfix server to pick the new changes by running the command below:

$ sudo service postfix restart

Step 5: Test the email sending functionality

We installed Postfix together with all associated mail utilities for sending emails. So we can use the command below to test if our email server is working as expected. To do this, run the command below:

$ echo "This email confirms that Postfix is working" | mail -s "Testing Posfix" emailuser@example.com

Remember to replace emailuser@example.com with the right address where you want the email to be sent. You can send the email to your Yahoo, Google or Microsoft account.

You can now go ahead and check your email address and see if the email was delivered successfully. Remember to check the spam folder

Conclusion

That’s all when it comes to configuring and setting up Postfix as an email server on your Ubuntu 18.04 VPS. If you get any problems, check with your hosting provider if they block port 25 and if they do ask them if they can enable it for you. If you followed the guide, email notifications from your server should work pretty well without any problems.

Check out these top 3 VPS services:

Kamatera
$4.00 /mo
Starting price
Visit Kamatera
Rating based on expert review
  • User Friendly
    3.5
  • Support
    3.0
  • Features
    3.9
  • Reliability
    4.0
  • Pricing
    4.3
Hostinger
$2.99 /mo
Starting price
Visit Hostinger
Rating based on expert review
  • User Friendly
    4.7
  • Support
    4.7
  • Features
    4.8
  • Reliability
    4.8
  • Pricing
    4.7
Liquid Web
$5.00 /mo
Starting price
Visit Liquid Web
Rating based on expert review
  • User Friendly
    3.8
  • Support
    4.8
  • Features
    4.5
  • Reliability
    4.6
  • Pricing
    3.8

*  Explore more about the best and recommended VPS providers

How To Set up a VSFTPD Server on a CentOS 7 VPS or Dedicated Server

Brief Description FTP is usually insecure exposing clear-text passwords, userna
2 min read
Eliran Ouzan
Eliran Ouzan
Web Designer & Hosting Expert

How To Set up a VSFTPD Server on an Ubuntu 16.04 VPS or Dedicated Server

Brief Description FTP data is usually insecure since information (usernames, pa
2 min read
Eliran Ouzan
Eliran Ouzan
Web Designer & Hosting Expert

How to use phpMyAdmin to develop a website (without MySQL experience)

Brief description A web developer who is not well versed into coding websites f
2 min read
Idan Cohen
Idan Cohen
Marketing Expert

How to Install MySQL on a Windows Web Server Running Apache

This tutorial will show you how to install the MySQL database on a Windows serve
3 min read
Michael Levanduski
Michael Levanduski
Expert Hosting Writer & Tester
HostAdvice.com provides professional web hosting reviews fully independent of any other entity. Our reviews are unbiased, honest, and apply the same evaluation standards to all those reviewed. While monetary compensation is received from a few of the companies listed on this site, compensation of services and products have no influence on the direction or conclusions of our reviews. Nor does the compensation influence our rankings for certain host companies. This compensation covers account purchasing costs, testing costs and royalties paid to reviewers.
Click to go to the top of the page
Go To Top