Postfix is a popular, high-performance Mail Transfer Agent (MTA) that routes and delivers email. This guide installs and configures Postfix as an outgoing SMTP server on Ubuntu 24.04 LTS.
Tested and valid on:
- Ubuntu 24.04 LTS
Prerequisites
- Ubuntu 24.04 LTS server
- A registered domain name
- DNS MX records pointing to your server
- A user with sudo privileges
Step 1 – Install Postfix
Install Postfix:
sudo apt update
sudo apt install postfix mailutils -y
In the setup dialog, select Internet Site and enter your domain name.
Step 2 – Configure Postfix
Edit the main configuration:
sudo nano /etc/postfix/main.cf
Key settings:
myhostname = mail.example.com
mydomain = example.com
myorigin = $mydomain
inet_interfaces = all
mydestination = $myhostname, $mydomain, localhost.$mydomain, localhost
relayhost =
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
Step 3 – Restart Postfix
Apply changes:
sudo systemctl restart postfix
sudo systemctl enable postfix
Step 4 – Test Sending Email
Send a test email from the command line:
echo 'Test email from Ubuntu 24.04' | mail -s 'Postfix Test' [email protected]
Step 5 – Check the Mail Queue
View and manage the mail queue:
mailq
postqueue -f # flush the queue
Step 6 – Configure TLS for SMTP
Enable TLS encryption in Postfix:
sudo nano /etc/postfix/main.cf
Add:
smtpd_tls_cert_file=/etc/ssl/certs/mysite.crt
smtpd_tls_key_file=/etc/ssl/private/mysite.key
smtpd_tls_security_level=may
smtp_tls_security_level=may
Restart:
sudo systemctl restart postfix
Step 7 – View Mail Logs
Monitor Postfix activity:
sudo tail -f /var/log/mail.log
Conclusion
Postfix is now running on Ubuntu 24.04 LTS. For a complete mail server, pair Postfix with Dovecot for IMAP access, SpamAssassin for spam filtering, and OpenDKIM for email authentication.