Install Postfix Mail Server on Ubuntu 22.04

In this guide, we want to show you How To Install and Configure Postfix Mail Server on Ubuntu 22.04.

Postfix is open-source software (IBM Public License or Eclipse Public License), a mail transfer agent (MTA) that you can download and use on different OSes like Linux (Ubuntu, Debian, CentOS, etc.), BSD (including FreeBSD), macOS, Solaris, HP-UX, AIX. 

It offers an SMTP server and SMTP client, so it could directly receive and send emails. Having some spam protection, it could work together with other software products like Amavisd-new, Dovecot, Mailman, and more. 

The server runs in the background and contains different components like a scheduler, local delivery server, address re-writer, and more. The client side is used by the users to send emails. 

You can find Postfix as the default MTA for Ubuntu, CentOS, RedHat, Fedora, NetBSD, macOS, and more. 

Install and Configure Postfix Mail Server on Ubuntu 22.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 22.04.

Install Postfix on Ubuntu 22.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

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.

Postfix Configuration
Postfix Configuration

Then, you need to enter your FQDN (Fully Qualified Domain Name) as your mail-domain name.

System mail name
System 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      3382/master
tcp6       0      0 :::25                   :::*                    LISTEN      3382/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 22.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.

Postfix configuration Ubuntu
Postfix Configuration

Then, you need to enter your FQDN (Fully Qualified Domain Name) as your mail-domain name again.

System mail name on ubuntu 22.04
System Mail Name

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 “[email protected]” and replace the user and domain names with those you have.

Postmaster mail account
Postmaster Mail Account

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.

Postfix mail destination
Postfix Mail Destinations

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.

synchronous updates for Postfix
synchronous updates

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 on or set up a third-party mail service for relaying purposes.

Postfix local networks Ubuntu 22.04
Local Networks

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 as per your preferences. After doing so, Postfix will currently be configured with your settings.

Reload Postfix

Reload the postfix mail server on Ubuntu 22.04 to apply the changes:

sudo systemctl reload postfix

You have now configured the basic settings of Postfix on your domain.

How To Test Postfix Installation

Since we have set up only the localhost mail server, 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: <[email protected]>

To: <[email protected]>

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 Install and Configure Postfix on Ubuntu 22.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:

How To Install PHP 8.2 on Ubuntu 22.04

How To Install Python 3.11 on Ubuntu 22.04

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Leave a Reply

Your email address will not be published. Required fields are marked *

Stay informed and not overwhelmed, subscribe now!