In this tutorial, you will learn how to install and configure Postfix on your server, so that other applications installed on that server can use the Postfix to send emails.
Why you need Postfix?
If you are already using a third-party service provider like Sendgrid, Pepipost etc to send emails, then you really don't need a Postfix. But, if you are not using a third party and want to set up something on your local server which can help you to send emails at scale, then you can use Postfix for that purpose.
Postfix is one of the most popular open-source Mail Transfer Agent (MTA) which route and delivers mails.
- One Debian 10 server, and a sudo non-root user.
- One valid domain name eg: mycompany.com, which should be pointing to your Debian 10 server.
Note, the hostname of your machine must match your domain name. And, in order to check the same you can run the following command:
The output should show the domain name e.g. mycompany.com which you have pointed to this server.
Step 1 - Install Postfix
Just confirm your Debian server version first using the below
The output should show Debian 10.
The next step is two install two important packages:
mailutils, which includes programs necessary for Postfix to function, and the
Let's first update the Package Database itself:
sudo apt update
mailutils a package which postfix requires to function properly.
sudo apt install mailutils
Finally, install the
postfix package itself:
sudo apt install postfix
Once all the package is downloaded you will see a screen like the one below which will be asking you to choose the type of configuration. Press Enter to see next screen which shows options to select.
Mainly there are 4 configurations
- Internet site
- Internet with smarthost
- Satellite system
- Local Only
The default option is the Internet Site and that’s the recommended one for this tutorial too. So, press
ENTER to continue with the installation.
Select Internet Site and press OK. you will be asked to enter the System mail name, which is actuall the domain name. Enter your domain (which you mapped to this server earlier at the start of this tutorial) and then press
If it shows a subdomain like
subdomain.yourcompany.com, change it to just
yourcompany.com. When you’ve finished, press
Now, your postfix is successfully installed on your Debian 10 machine. Now, the next steps is to configure the Postfix by modifying its settings.
Step 2- Configuring Postfix as send-only SMTP server
In this step, you will be going to configure Postfix as a send-only SMTP server i.e. it should process requests to send emails only from the server on which is it is running, i.e. from
For that to happen, Postfix needs to be configured to listen only on the loopback interface, the virtual network interface that the server uses to communicate internally. To make those changes, you need to open the Postfix's main configuration file
main.cf. You can use your favourite editor
nano to open the same.
sudo nano /etc/postfix/main.cf
You need to make the following changes in the configuration. Locate for the below sections and change as per the instructions below:
inet_interfaces = all to inet_interfaces = loopback-only
Inet_interface in main.cf is used to control addresses postfix listens for incoming addresses, specifying this to loopback-only means that connection can only originate from that machine where postfix is installed.
Once the file is changed, save it. And restart postfix
sudo systemctl restart postfix
Another parameter, you’ll need to modify is
mydestination, which is used to specify the list of domains that are delivered via the
local_transport mail delivery transport. By default, the values are similar to these:
mydestination = $myhostname, example.com, localhost.com, localhost
Change the above values with the one suggested below:
mydestination = $myhostname, localhost.$your_domain, $your_domain
Save and close the file.
Now you have configured postfix successfully.
Step 3- Testing SMTP server
Now we’ll test whether our SMTP server can send emails to an external account using
echo "This is the body of the email" | mail -s "This is the subject line" email_address
Change body and subject line accordingly and in place of email address use valid email id.
Check the inbox or spam folder of your mailbox where you sent the email.
Note that with this configuration, the address in the From field for the test emails you send will be
email@example.com, where yourusername is your Linux username and
mycompany.com is the domain set in your server’s hostname. If you change your username, the From address will also change.
You can also check the email sending logs in /var/log/mail.log
That's all, you have successfully installed and configured postfix as send-only SMTP server. Please feel free to share your learnings below in comments. We would love to add those as a part of this tutorial. Further if your go to Configure Postfix Send Mail Using an External SMTP Server which is an extended tutorial catering to Send mail.