A Postfix SMTP server on Ubuntu VPS gives you direct control over outgoing email, DNS settings, and mail logs. This tutorial covers a basic Postfix installation on Ubuntu 24.04 LTS, plus the security and authentication steps needed before production use.
Step 1: Prepare Your Ubuntu VPS and Domain
Start with an updated VPS, root or sudo access, a domain, and a dedicated public IP. Choose a hostname such as mail.example.com, then point its DNS A record to your server. Ask your provider to set the IP’s PTR/rDNS record to the same hostname.
For direct server-to-server delivery, outbound TCP port 25 must be available. CybroHost SMTP VPS Hosting provides self-managed Linux servers with port 25 access and PTR/rDNS control.
Set the hostname:
sudo hostnamectl set-hostname mail.example.com
Step 2: Install Postfix on Ubuntu
Connect over SSH and run:
sudo apt update
sudo apt install postfix mailutils -y
During installation, select Internet Site and enter example.com as the system mail name. This creates the initial configuration in /etc/postfix/main.cf.
Step 3: Configure Postfix Safely
Set the server’s mail identity and enable SMTP listening:
sudo postconf -e 'myhostname = mail.example.com'
sudo postconf -e 'myorigin = example.com'
sudo postconf -e 'inet_interfaces = all'
sudo postconf -e 'smtpd_relay_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination'
The last setting rejects unauthorized relaying. Do not trust public networks in mynetworks, or you could expose an open relay. Postfix is not yet configured for authenticated application logins.
Step 4: Add TLS Encryption
For a public mail service, obtain a valid TLS certificate for mail.example.com, then configure its certificate and private-key paths in Postfix. Enable opportunistic STARTTLS for server-to-server mail. Ubuntu’s official Postfix setup guide explains the TLS and SASL options.
If applications or remote users must submit mail on port 587, configure authenticated submission with SASL (commonly using Dovecot), enforce TLS on that submission service, and open the port only after securing it.
Step 5: Restart and Test Email Delivery
Check the configuration, restart Postfix, and send a test message:
sudo postfix check
sudo systemctl restart postfix
echo 'Postfix test' | mail -s 'SMTP test' recipient@example.net
Allow TCP port 25 through your firewall when receiving SMTP connections is required. Review failures with sudo journalctl -u postfix -n 50 and inspect the queue using mailq. A successfully queued message does not guarantee inbox delivery.
Step 6: Configure Email Authentication
Publish an SPF TXT record authorizing your VPS IP. Install a DKIM signer, such as OpenDKIM, and publish its public key. Add DMARC, initially with p=none for monitoring. If you receive incoming mail, also point your domain’s MX record to mail.example.com.
Final Recommendation
A Postfix SMTP server on Ubuntu VPS is a flexible starting point, but secure relay controls, TLS, matching DNS, authentication, and careful testing are essential before handling real email traffic.
FAQs
Is Postfix free to use?
Yes. Postfix is open-source mail transfer software; you pay for the VPS, domain, and any supporting services.
Can Postfix send email through port 587?
Yes, after you configure an authenticated submission service. A default installation does not automatically provide secure logins for external applications.
Why are messages going to spam?
Possible causes include missing SPF, DKIM, DMARC, or PTR records; poor sender reputation; or unwanted sending patterns. Check authentication results and delivery logs first.
