Install and configure Postfix as Send-Only SMTP on Debian 11

This guide is going to take you through on how to Install and configure Postfix as Send-Only SMTP on Debian 11. Postfix is a mail transfer agent (MTA), or email sending and receiving application. It can be configured to send emails solely from a local application. This is critical if you frequently send email notifications from your apps or if you have a lot of outgoing traffic that a third-party email service provider won’t allow you to send. It’s also a less resource-intensive alternative to running a full-fledged SMTP server while maintaining all of the necessary features.

How to Install and configure Postfix as Send-Only SMTP on Debian 11

Make sure your packages are up to date by updating using the command below.

sudo apt update

Install Postfix on Debian 11

  • Install mailutils, which is required for Postfix to work properly.
sudo apt install mailutils

Sample output

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
  liblightdm-gobject-1-0 lightdm-gtk-greeter
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  exim4-base exim4-config exim4-daemon-light gsasl-common
  libgnutls-dane0 libgsasl7 libmailutils7 libmariadb3 libntlm0
  libunbound8 mailutils-common mariadb-common mysql-common
Suggested packages:
  exim4-doc-html | exim4-doc-info eximon4 spf-tools-perl swaks
  mailutils-mh mailutils-doc
The following NEW packages will be installed:
  exim4-base exim4-config exim4-daemon-light gsasl-common
  libgnutls-dane0 libgsasl7 libmailutils7 libmariadb3 libntlm0
  libunbound8 mailutils mailutils-common mariadb-common
  mysql-common
0 upgraded, 14 newly installed, 0 to remove and 0 not upgraded.
Need to get 5,938 kB of archives.
After this operation, 13.2 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://deb.debian.org/debian bullseye/main amd64 exim4-config all 4.94.2-7 [335 kB]
Get:2 http://deb.debian.org/debian bullseye/main amd64 exim4-base amd64 4.94.2-7 [1,175 kB]
Get:3 http://deb.debian.org/debian bullseye/main amd64 libunbound8 amd64 1.13.1-1 [504 kB]
Get:4 http://deb.debian.org/debian bullseye/main amd64 libgnutls-dane0 amd64 3.7.1-5 [394 kB]
Get:5 http://deb.debian.org/debian bullseye/main amd64 exim4-daemon-light amd64 4.94.2-7 [658 kB]
Get:6 http://deb.debian.org/debian bullseye/main amd64 gsasl-common all 1.10.0-4 [175 kB]
Get:7 http://deb.debian.org/debian bullseye/main amd64 libntlm0 amd64 1.6-3 [84.7 kB]
Get:8 http://deb.debian.org/debian bullseye/main amd64 libgsasl7 amd64 1.10.0-4 [195 kB]
Get:9 http://deb.debian.org/debian bullseye/main amd64 mailutils-common all 1:3.10-3 [728 kB]
Get:10 http://deb.debian.org/debian bullseye/main amd64 mysql-common all 5.8+1.0.7 [7,464 B]
Get:11 http://deb.debian.org/debian bullseye/main amd64 mariadb-common all 1:10.5.15-0+deb11u1 [36.7 kB]
Get:12 http://deb.debian.org/debian bullseye/main amd64 libmariadb3 amd64 1:10.5.15-0+deb11u1 [176 kB]
Get:13 http://deb.debian.org/debian bullseye/main amd64 libmailutils7 amd64 1:3.10-3+b1 [893 kB]
Get:14 http://deb.debian.org/debian bullseye/main amd64 mailutils amd64 1:3.10-3+b1 [576 kB]
Fetched 5,938 kB in 2s (3,097 kB/s)
Preconfiguring packages ...
  • Next Install Postfix using the following command.
sudo apt install postfix

Sample output

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libgnutls-dane0 liblightdm-gobject-1-0 libunbound8
  lightdm-gtk-greeter
Use 'sudo apt autoremove' to remove them.
Suggested packages:
  procmail postfix-mysql postfix-pgsql postfix-ldap postfix-pcre
  postfix-lmdb postfix-sqlite sasl2-bin | dovecot-common
  resolvconf postfix-cdb postfix-doc
The following packages will be REMOVED:
  exim4-base exim4-config exim4-daemon-light
The following NEW packages will be installed:
  postfix
0 upgraded, 1 newly installed, 3 to remove and 0 not upgraded.
Need to get 1,540 kB of archives.
After this operation, 56.3 kB disk space will be freed.
Do you want to continue? [Y/n] y
Get:1 http://deb.debian.org/debian bullseye/main amd64 postfix amd64 3.5.6-1+b1 [1,540 kB]
Fetched 1,540 kB in 1s (1,797 kB/s)
Preconfiguring packages ...
(Reading database ... 142339 files and directories currently installed.)
Removing exim4-daemon-light (4.94.2-7) ...
Removing exim4-base (4.94.2-7) ...
Removing exim4-config (4.94.2-7) ...
Selecting previously unselected package postfix.
(Reading database ... 142206 files and directories currently installed.)
Preparing to unpack .../postfix_3.5.6-1+b1_amd64.deb ...
Unpacking postfix (3.5.6-1+b1) ...
Setting up postfix (3.5.6-1+b1) ...
Adding group `postfix' (GID 128) ...
Done.
  • Select your preferred settings when prompted according to your preference e.g. Internet Site
  • Next set your system mail name i.e. your domain name.
  • If the config above doesn’t show during Postfix installation for some reason, or if you wish to rerun it, use the following command to open it.
sudo dpkg-reconfigure postfix

Configure Postfix as Send-Only SMTP on Debian 11

  • To configure Postfix on Debian 11, open the configuration file in your preferred text editor.
sudo nano /etc/postfix/main.cf
  • Set your hostname to myhostname and mydestination in the config file, then set the value of inet interface to loopback-only. Take a look at the example configuration below.
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authentic>
myhostname = debian
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
mydestination = $myhostname, your_domain, debian, localhost.locald>
relayhost =
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = loopback-only
inet_protocols = all
  • If you’re using a subdomain and want emails to look like they came from the main domain, add the following line to the config file.
masquerade_domains = your_main_domain
  • Next restart Postflix for changes to take effect.
sudo systemctl reload postfix
sudo systemctl restart postfix
  • Check Post fix status.
sudo systemctl status postfix

Sample output

● postfix.service - Postfix Mail Transport Agent
     Loaded: loaded (/lib/systemd/system/postfix.service; enabled; vendor preset: enabled)
     Active: active (exited) since Tue 2022-04-12 16:07:25 EAT; 1min 14s ago
    Process: 7944 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
    Process: 7970 ExecReload=/bin/true (code=exited, status=0/SUCCESS)
   Main PID: 7944 (code=exited, status=0/SUCCESS)
        CPU: 1ms

Apr 12 16:07:25 debian systemd[1]: Starting Postfix Mail Transport Agent...
Apr 12 16:07:25 debian systemd[1]: Finished Postfix Mail Transport Agent.
Apr 12 16:08:38 debian systemd[1]: Reloading Postfix Mail Transport Agent.
Apr 12 16:08:38 debian systemd[1]: Reloaded Postfix Mail Transport Agent.

Test the SMTP server on Debian 11

  • To see if your server sends mail, run the command below.
echo "This is the body of the email" | mail -s "This is the subject of the email" [email protected]

The recipient should receive the email send, check in Junk/Spam folder incase it’s not in the inbox.

Forward System Mails

  • You must configure system mail forwarding in order to receive system mails, i.e. mails sent to root user on an external mail account. System-generated mails are sent to the root user on the local system by default as defined by /etc/aliases configuration file. Open the configuration file using the command below.
sudo nano  /etc/aliases
  • Then add the following line in the config file. Note, change your_email_address with your real address.
root:  your_email_address
  • Run the following command for changes to take effect.
sudo newaliases
  • Send a test email to ensure that the modifications are working.
echo "Testing Mail Forwarding to Postfix SMTP" | mail -s "Forward System Mails" root
  • You’ve made it to the end of the article, Cheers. You have learned how to install and configure Postfix as Send-Only SMTP on Debian 11.

Read more on Postfix Documentation

Other Tutorial

Install Filebeat 8 on Rocky Linux

Install ELK Stack 8 on Rocky Linux

Install Thunderbird mail client on Debian 10

System administrator | Software Developer | DevOps

Leave a Comment