Configure Postfix as a Send-Only SMTP Server on Ubuntu 20.04
Abstract: Postfix is an open-source Mail Transport Agent (MTA). An MTA is a component of the Simple Mail Transfer Protocol (SMTP) responsible for transferring m
Postfix is an open-source Mail Transport Agent (MTA). An MTA is a component of the Simple Mail Transfer Protocol (SMTP) responsible for transferring mail from one mail server to another.
This tutorial describes how you can install and configure Postfix as a send-only SMTP server on Ubuntu 20.04. You can use this for sending notification emails to an external address when specific events occur on the server -- such as when a backup job succeeds or fails.
Prerequisites- Ubuntu 20.04 server
- A user with sudo privileges
- A registered domain name pointing to your server's public IP address
A fully qualified domain name comprises a hostname and a domain name. For example, mail.domain.com -- where mail is the hostname and domain.com is the domain name. The FQDN uniquely identifies your server on the Internet.
Send Free Unlimited Emails | SMTP S...To view this video please enable JavaScript, and consider upgrading to a web browser that supports HTML5 video
Send Free Unlimited Emails | SMTP Server Setup on Ubuntu Virtualmin | Outgoing Mail Server on OCPFirstly, run the command below to open the hostname file for editing.
$ sudo nano /etc/hostname
Next, delete the existing entry if you do not want to use that, and enter your desired hostname (e.g. mail or smtp). After that, save your changes and close the hostname file.
To configure the domain name part, run the command below.
$ sudo nano /etc/hosts
In this file, you need to specify your server's public IP address, the FQDN, and the hostname. The following is an example.
127.0.0.1 localhost
127.0.1.1 smtp.domain.com smtp
192.1.2.3 smtp.domain.com smtp
Save your changes and close the hosts file.
Install and Configure PostfixNow, let us proceed to install and configure Postfix. Run the command below to check for package updates.
$ sudo apt update
Next, run the command below to install mailutils which is a collection of mail utilities, including Postfix.
$ sudo apt install mailutils -y
At the initial Postfix package configuration screen, read the information displayed and press enter to proceed.
Postfix Package Configuration ScreenOn the next screen, the default selection should be Internet Site. This is fine because our goal is to send emails across the Internet. Press the tab key to move the selection to Ok and then press enter.
Postfix Mail Type ConfigurationNext, the system mail name may already be populated for you based on your server’s FQDN. Delete the host part so it becomes your domain.com
only.
Press the tab key to select Ok and then press enter to complete the installation.
Run the next command to check the status of Postfix.
$ sudo systemctl status postfixPostfix Service Status
To ensure that postfix is automatically started whenever the server is rebooted, run:
$ sudo systemctl enable postfix
Now, open the main Postfix configuration file with the following command.
$ sudo nano /etc/postfix/main.cf
In this file, look for inet_interfaces and set the value to loopback-only. This will ensure that Postfix will only listen on the localhost interface and can prevent it from being used as an open relay.
Save your changes and close the main.cf file.
Reload Postfix configuration with the next command:
$ sudo systemctl reload postfixTest Postfix
To test Postfix, run the command below. The most important thing here is to replace [email protected] with a valid external recipient address where this test message will be delivered.
$ echo "This is the message body to test Postfix" | mail -afrom:[email protected] -s "This is the message subject to test Postfix" [email protected]
Check your external mailbox to confirm if the message was delivered. It would most likely be placed in the junk/spam folder.
Postfix Test Message ConclusionIn this tutorial, we have described the steps to install and configure Postfix as a send-only SMTP server on Ubuntu 20.04. This tutorial focused on the basic configuration of Postfix. To learn more, see the Postfix documentation.