Set up Postfix Mail Server on Ubuntu 20.04: Best Mail Server
In this guide, we want to teach you how 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.
Now follow the guide steps below on the Orcacore website to complete the Set up Postfix Mail Server on Ubuntu 20.04 setup.
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.
1. 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.
2. Configure Postfix on Ubuntu 20.04
If you plan to configure your Postfix mail server 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.
3. 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 the Postfix mail server.
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 <<mark>user-name</mark>@<mark>sender-domain.com</mark>>
Replace the “user-name” and “sender-domain.com” with the appropriate values.
rcpt to <<mark>user-name</mark>>
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 Mail Server on Ubuntu 20.04. Also, you have learned to test your Postfix. This guide provides a solid foundation for configuring Postfix as a basic mail server.
Hope you enjoy it. Also, you may be interested in these articles:
Set up OpenNMS on Ubuntu 20.04
Install Pritunl VPN Server and Client on Ubuntu 20.04
OpenJDK 19 Setup For Ubuntu 20.04
Installing Apache Maven on Ubuntu 20.04
Get PHP 8.2 For Ubuntu 20.04
Python 3.11 Setup on Ubuntu 20.04
Remote Access To Git Repos with GitLab on Ubuntu 20
Alternative Solutions for Setting Up a Mail Server on Ubuntu 20.04
While Postfix is a powerful and flexible MTA, it can be complex to configure, especially for beginners. Here are two alternative solutions for setting up a mail server on Ubuntu 20.04, each offering a different approach to ease of use and functionality:
1. Using Mail-in-a-Box
Mail-in-a-Box is an open-source mail server solution designed to be incredibly easy to set up and maintain. It automates much of the configuration process, providing a fully functional mail server with minimal user intervention. It handles not only MTA functions but also includes webmail, DNS configuration, and spam filtering.
Explanation:
Mail-in-a-Box simplifies the setup process by bundling all necessary components and configurations into a single package. It automatically configures DNS records, sets up TLS certificates (using Let’s Encrypt), and configures spam and antivirus filtering. This reduces the need for manual configuration of each individual component, making it an ideal solution for users who want a hassle-free mail server setup.
Installation and Configuration:
-
Download and Run the Installer:
First, download the Mail-in-a-Box installer script:
curl -s https://mailinabox.email/setup.sh | sudo bash
-
Follow the Prompts:
The script will guide you through the setup process, asking for your domain name, admin email address, and desired hostname.
-
DNS Configuration:
Mail-in-a-Box will recommend DNS settings that you need to configure with your domain registrar. This is crucial for mail delivery.
-
Access the Admin Panel:
After installation, you can access the Mail-in-a-Box admin panel through a web browser to manage users, domains, and other settings.
Pros:
- Extremely easy to set up and use.
- Automates DNS configuration and TLS certificate management.
- Includes webmail interface.
- Provides built-in spam and antivirus filtering.
Cons:
- Less flexible than Postfix for advanced configurations.
- Relies on a specific configuration style, which may not suit all users.
- Can be resource-intensive compared to a minimal Postfix setup.
2. Using Sendinblue (or Similar Transactional Email Services)
This approach doesn’t involve setting up a full mail server on your Ubuntu 20.04 machine. Instead, it leverages a third-party transactional email service like Sendinblue, Mailgun, or Amazon SES to handle sending emails. This is particularly useful if you primarily need to send emails from your applications (e.g., password resets, notifications) and don’t require a full-fledged mail server for receiving emails.
Explanation:
Transactional email services provide an API that your applications can use to send emails. These services handle the complexities of email delivery, including authentication (SPF, DKIM, DMARC), deliverability, and bounce management. This significantly simplifies the process of sending emails from your server and ensures a higher deliverability rate compared to directly sending emails from a self-hosted mail server.
Example using Sendinblue API (Python):
First, install the Sendinblue Python library:
pip install sib-api-v3-sdk
Then, use the following Python code to send an email:
import sib_api_v3_sdk
from sib_api_v3_sdk.rest import ApiException
# Configure API key authorization: api-key
configuration = sib_api_v3_sdk.Configuration()
configuration.api_key['api-key'] = 'YOUR_SENDINBLUE_API_KEY' # Replace with your actual API key
# Create an instance of the API class
api_instance = sib_api_v3_sdk.TransactionalEmailsApi(sib_api_v3_sdk.ApiClient(configuration))
# Define the email parameters
subject = "Password Reset Request"
sender = {"name": "Your Application", "email": "noreply@yourdomain.com"}
recipient = [{"email": "user@example.com"}] # Replace with recipient's email
content = [{"type": "text/plain", "value": "Please click on the following link to reset your password: https://yourdomain.com/reset-password"}]
send_smtp_email = sib_api_v3_sdk.SendSmtpEmail(to=recipient, sender=sender, subject=subject, html_content=content[0]['value'], text_content=content[0]['value'])
try:
# Send a transactional email
api_response = api_instance.send_transac_email(send_smtp_email)
print(api_response)
except ApiException as e:
print("Exception when calling TransactionalEmailsApi->send_transac_email: %sn" % e)
Replace YOUR_SENDINBLUE_API_KEY
with your actual Sendinblue API key.
Pros:
- Simplified email sending from applications.
- Improved deliverability due to managed infrastructure and reputation.
- Handles authentication (SPF, DKIM, DMARC) automatically.
- Scalable and reliable.
Cons:
- Requires relying on a third-party service.
- Cost can increase with the volume of emails sent.
- Primarily suitable for transactional emails, not for setting up a full mail server for receiving and managing emails.
These alternative solutions offer different approaches to setting up a mail server on Ubuntu 20.04, catering to varying needs and technical skill levels. Mail-in-a-Box provides an all-in-one solution for easy setup, while transactional email services simplify email sending from applications with improved deliverability. The best choice depends on your specific requirements and priorities. You have successfully learned how to Set up Postfix Mail Server on Ubuntu 20.04 as well as alternative methods.