Share your love
Set up Postfix Mail Server on Ubuntu 20.04
In this guide, we want to teach you to Set up Postfix Mail Server on Ubuntu 20.04.
Postfix is an MTA and handles the delivery of messages between servers and locally within a system. It does not handle any POP or IMAP communications.
You can find Postfix as the default MTA for Ubuntu, CentOS, RedHat, Fedora, NetBSD, macOS, and more.
Steps To Set up Postfix Mail Server on Ubuntu 20.04
To complete this guide, you must log in to your server as a non-root user with sudo privileges. To do this, you can follow our guide on Initial Server Setup with Ubuntu 20.04.
Install Postfix on Ubuntu 20.04
As you know, Postfix packages are available in the default Ubuntu repository. First, you need to run the system update:
sudo apt update
Then, you need to check which MTA you have installed on your server with the following command:
sudo netstat -ltnp | grep :25
In my case, I don’t have anything installed on my server.
Now you can use the command below to install Postfix on your server:
sudo apt install postfix -y
During the installation, you will be asked to choose your general type of mail configuration. You can choose “Internet Site” and press ok to install Postfix with the default values.
Then, you need to enter your FQDN (Fully Qualified Domain Name) as your mail name.
When your installation is completed, you can verify it by using the command below:
netstat -ltnp | grep :25
Output
tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN 2609/master
tcp6 0 0 :::25 :::* LISTEN 2609/master
This confirms that the Postfix has been installed successfully. Postfix is also known as Master, so do not get confused with “netstat” results on port 25.
Also, you can see that Postfix is running correctly by checking the mail logs, errors, or info:
# sudo cat /var/log/mail.log
# sudo cat /var/log/mail.errors
# sudo cat /var/log/mail.info
The above commands will show you the relevant results to briefly look at the Postfix in action.
Configure Postfix on Ubuntu 20.04
If you plan to configure your Postfix installation, you need to run the following command:
sudo dpkg-reconfigure postfix
You will be prompted to select the mail server config type again and select “Internet Site” again.
Then, you need to enter your FQDN (Fully Qualified Domain Name) as your mail name again.
After setting up the mail domain, you will be asked to set up the user account of the system administrator, where all the mail will be redirected to. You can use this format “user@domain-name.com” and replace the user and domain names with those you have.
Next, you need to enter all the domains for which you want to receive the emails, and you also need to include the top-level domain.
At this point, you will be asked to choose whether to allow forced synchronous updates or not. If you want faster processing, you should keep it as “NO.” It will come with a bit of risk of losing some emails during crashes, but with higher speeds, so it depends on your preference.
Now you will be prompted to select the network blocks for relaying mail. You can keep the default values for the Postfix mail server configuration to keep the host forwarding the emails to the local host. You can change it manually later or set up a third-party mail service for relaying purposes.
From here three prompts will be for the mailbox size limit, local address extension character, and internet protocol selection. You can keep the default values for now or set your own per your preferences. After doing so, Postfix will currently be configured with your settings.
Reload Postfix
At this point, reload the postfix mail server on Ubuntu 20.04 to apply the changes:
sudo systemctl reload postfix
You have now configured the basic settings of Postfix on your domain.
How To Use Postfix Mail Server on Ubuntu 20.04
Since we have set up only the localhost mail server, we will test it by running the telnet command on port 25 and see if the mail server is connected correctly.
Note: You can change localhost with your domain set up with Postfix.
telnet localhost 25
Output
Trying ::1...
Connected to localhost.
Escape character is '^]'.
220 deb.orca ESMTP Postfix (Ubuntu)
This shows that the connection has been successful with the mail server.
Now we want to send a test mail from a different domain to check if the mail is received correctly.
While staying connected to the mail server via Telnet, you need to run the following commands to create and send the test email:
mail from <user-name@sender-domain.com>
Replace the “user-name” and “sender-domain.com” with the appropriate values.
rcpt to <user-name>
Replace this “user-name” with the root username account of your mail server. Now type “data” to enter email data and press ENTER.
data
At this point, enter the email data as follows:
From: <user-name@sender-domain.com> To: <user-name@receiver-domain.com> Subject: Enter your email subject here Enter the body of the email here and then press ENTER.
To end the Telnet connection, type “.” and press ENTER. Then type “quit” and press ENTER again.
.
quit
You can now check the inbox and see if you successfully received the test email sent from the other domain. You can execute the “mail” command to do so.
mail
For more information, you can visit the Postfix Documentation page.
Conclusion
At this point, you have learned to Set up Postfix on Ubuntu 20.04. Also, you have learned to test your Postfix.
Hope you enjoy it. Also, you may be interested in these articles on the Orcacore website: