Install and Configure Postfix as Send-Only SMTP on Ubuntu 22.04

This guide is going to take you through on how to install and configure Postfix as Send-Only SMTP on Ubuntu 22.04. Postfix is a mail transfer agent (MTA), or email sending and receiving application. It can be set up such that it can only send emails from a local application. This is important if you need to send email notifications from your apps on a frequent basis or if you have a lot of outbound traffic that a third-party email service provider won’t let you send. It’s also a less resource-intensive alternative to hosting a full-fledged SMTP server while still providing the necessary capabilities.

How to Install and configure Postfix as Send-Only SMTP on Ubuntu 22.04

  • Make sure your packages are up to date by updating using the command below.
sudo apt update

Install Postfix on Ubuntu 22.04

  • Install Postfix on Ubuntu 22.04 suing the following command.
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:
  fonts-open-sans i965-va-driver intel-media-va-driver kwayland-data libaacs0 libavcodec58 libavformat58 libavutil56 libbdplus0 libbluray2 libchromaprint1 libcodec2-1.0 libdouble-conversion3 libgme0
  libgsm1 libigdgmm12 libkf5waylandclient5 libmd4c0 libmfx1 libminizip1 libmng2 libnorm1 libopenal-data libopenal1 libopenmpt0 libpcre2-16-0 libpgm-5.3-0 libqrcodegencpp1 libqt5core5a libqt5dbus5
  libqt5gui5 libqt5network5 libqt5svg5 libqt5waylandclient5 libqt5widgets5 librabbitmq4 librlottie0-1 libshine3 libsndio7.0 libsrt1.4-gnutls libssh-gcrypt-4 libswresample3 libswscale5 libudfread0
  libva-drm2 libva-x11-2 libva2 libvdpau1 libx264-163 libxcb-record0 libxcb-screensaver0 libxcb-xinerama0 libxcb-xinput0 libxvidcore4 libzmq5 libzvbi-common libzvbi0 mesa-va-drivers mesa-vdpau-drivers
  qt5-gtk-platformtheme qt5-image-formats-plugins qttranslations5-l10n va-driver-all vdpau-driver-all
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  gsasl-common guile-3.0-libs libgsasl7 libmailutils8 libntlm0 libpq5 mailutils-common
Suggested packages:
  mailutils-mh mailutils-doc
The following NEW packages will be installed:
  gsasl-common guile-3.0-libs libgsasl7 libmailutils8 libntlm0 libpq5 mailutils mailutils-common
0 upgraded, 8 newly installed, 0 to remove and 0 not upgraded.
Need to get 8,912 kB of archives.
After this operation, 59.3 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 jammy/universe amd64 gsasl-common all 1.10.0-5 [59.8 kB]
Get:2 jammy/universe amd64 guile-3.0-libs amd64 3.0.7-1 [7,538 kB]
Get:3 jammy/universe amd64 libntlm0 amd64 1.6-4 [73.7 kB]
Get:4 jammy/universe amd64 libgsasl7 amd64 1.10.0-5 [71.1 kB]
Get:5 jammy/universe amd64 mailutils-common all 1:3.14-1 [382 kB]
Get:6 jammy/main amd64 libpq5 amd64 14.2-1ubuntu1 [139 kB]
Get:7 jammy/universe amd64 libmailutils8 amd64 1:3.14-1 [519 kB]
  • While installing, you will be prompted to set your server type. Choose according to your preference e.g. Internet Site
  • Next set your system mail name i.e. your domain name.
  • If for some reasons the config above doesn’t appear during Postfix installation or you want to rerun it, open it using the following command.
sudo dpkg-reconfigure postfix

Configure Postfix as Send-Only SMTP on Ubuntu 22.04

  • Open the Postfix configuration file in your preferred text editor to configure it on Ubuntu 22.04.
sudo nano /etc/postfix/
  • On the config file, set your hostname on myhostname and mydestination then set the value of inet_interface to be loopback-only. Check the sample config below.
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = itnixpro.localdomain
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = $myhostname, itnixpro.localdomain, localhost.localdomain, localhost
relayhost =
mynetworks = [::ffff:]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = loopback-only
  • Add the line below to the config file if you’re using a subdomain and want emails to appear as if they were sent from the main domain.
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 11:29:51 EAT; 8min ago
       Docs: man:postfix(1)
    Process: 15217 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
   Main PID: 15217 (code=exited, status=0/SUCCESS)
        CPU: 2ms

Apr 12 11:29:51 itnixpro systemd[1]: Starting Postfix Mail Transport Agent...
Apr 12 11:29:51 itnixpro systemd[1]: Finished Postfix Mail Transport Agent.

Test the SMTP server on Ubuntu 22.04

  • Use the command below to test if your server sends mail.
echo "This is the body of the email" | mail -s "This is the subject of the email" [email protected]

Your recipient will receive the test email.

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 config file.
sudo nano  /etc/aliases
  • Add the following line in the config file. Change your_email_address with your real address.
root:  your_email_address
  • Run the following command for changes to take effect.
sudo newaliases
  • Send test email to confirm changes 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 Ubuntu 22.04.

Read more on Postfix Documentation

Other Tutorials

Install Filebeat 8 on Rocky Linux

Install ELK Stack 8 on Rocky Linux

Install Thunderbird mail client on Rocky Linux

System administrator | Software Developer | DevOps

Leave a Comment