Postfix is a high-performance, secure, and widely used Mail Transfer Agent (MTA). It handles the SMTP protocol for sending and relaying email. This guide installs and configures Postfix as an internet-facing SMTP server on Ubuntu 26.04 LTS.

Tested and valid on:

  • Ubuntu 26.04 LTS

Prerequisites

  • Ubuntu 26.04 LTS with a fully qualified domain name (FQDN) configured
  • A user with sudo privileges
  • Port 25 unblocked by your ISP/hosting provider
  • A valid DNS A record and reverse PTR record

Step 1 – Set the Hostname

sudo hostnamectl set-hostname mail.example.com
echo '127.0.0.1 mail.example.com' | sudo tee -a /etc/hosts

Step 2 – Install Postfix

sudo apt update
sudo apt install postfix -y

Select Internet Site during installation and enter your domain name.

Step 3 – Configure main.cf

sudo nano /etc/postfix/main.cf

Key settings:

myhostname = mail.example.com
mydomain = example.com
myorigin = $mydomain
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, $mydomain
relayhost =
home_mailbox = Maildir/
smtp_tls_security_level = may
smtpd_tls_security_level = may
smtpd_tls_cert_file = /etc/letsencrypt/live/mail.example.com/fullchain.pem
smtpd_tls_key_file  = /etc/letsencrypt/live/mail.example.com/privkey.pem

Step 4 – Restart and Test

sudo systemctl restart postfix
sudo systemctl status postfix
echo 'Test email' | mail -s 'Test from Postfix' [email protected]

Step 5 – View Mail Queue

mailq
postqueue -p
postsuper -d ALL  # flush queue

Step 6 – Configure Virtual Mailboxes (optional)

sudo nano /etc/postfix/virtual

Add:

[email protected]  localuser
sudo postmap /etc/postfix/virtual
echo 'virtual_alias_maps = hash:/etc/postfix/virtual' | sudo tee -a /etc/postfix/main.cf
sudo systemctl reload postfix

Step 7 – Allow in UFW

sudo ufw allow 25/tcp
sudo ufw allow 587/tcp
sudo ufw allow 465/tcp

Conclusion

Postfix is installed and configured on Ubuntu 26.04 LTS. Combine it with Dovecot for IMAP access, SpamAssassin for spam filtering, and configure DKIM/SPF/DMARC to improve email deliverability.