In this guide, we intend to teach you to Install and Configure Postfix Mail Server on Debian 11.
Postfix is a hugely-popular Mail Transfer Agent (MTA) designed to determine routes and send emails. This cross-platform server is open-source, free, and suitable for installation on the majority of UNIX-like operating systems.
With Postfix, you can expect a significant degree of flexibility and simple administration, which makes it easier for beginners to set up than alternative MTA options. On top of this, Postfix offers support for Sendmail’s command line interface. It’s also compatible with a variety of Sendmail’s mail filters.
Steps To Install and Configure Postfix Mail Server on Debian 11
To install Postfix, you must log in to your server as a non-root user with sudo privileges. To do this, you can follow our guide the Initial Server Setup with Debian 11.
Now follow the steps below to complete this guide.
Install Postfix on Debian 11
First, you need to update your local package index with the following command:
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.
At this point, you can use the following command to install the postfix mail server:
sudo apt install postfix
Once you run the command, you will be asked to select one of the following options:
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-domain name.
When your installation is completed, you will get the following output:
Output Postfix (main.cf) is now set up with a default configuration. ...
You can verify your postfix installation on Debian 11 by running the following command:
netstat -ltnp |grep :25
Output tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN 19358/master tcp6 0 0 :::25 :::* LISTEN 19358/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.
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-domain 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 “[email protected]” 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 on 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 as per your preferences. After doing so, Postfix will currently be configured with your settings.
Reload postfix mail server on Debian 11 to apply the changes:
sudo systemctl reload postfix
You have now configured the basic settings of Postfix on your domain.
Test Postfix on Debian 11
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 (Debian/GNU)
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 <[email protected]>
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.
Now 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.
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.
As you can see from the examples, using the Postfix mail server is very practical and easy. Postfix is very flexible for mail server administrators and developers. Moreover, it’s compatible with many tools such as SQL, MySQL, Cyrus, LDAP, SASL, TSL, and SSL. Compared to other MTAs, it performs better even on systems with heavy traffic and several users.
Hope you enjoy it.
You may be interested in these articles:
Install and Configure Memcached on Debian 11
Set Up Password Authentication with Apache on Debian 11
Install Nagios Monitoring Tool on Debian 11
Install and Configure Lighttpd Web Server on Debian 11