Transactional email is the mail your users expect without thinking about it: password resets, order confirmations, receipts, account alerts. When one never arrives, the user blames your app, not your mail setup. That is why a mail server on a VPS deserves more care than a quick Postfix install and a hope for the best. Done right, it gives you full control over sending, logs and reputation; done carelessly, your mail lands in spam or never leaves the queue.
This transactional email setup guide covers the outbound-only configuration most small projects need: provider checks, Postfix install, the three DNS records that decide whether Gmail trusts you, and delivery tests before a real user depends on it.
What Transactional Email Actually Needs
Transactional mail differs from newsletters in two ways. First, each message is triggered by one user action, so volume is low and bursty: a store might send 20 receipts on a quiet day and 400 after a sale. Second, the messages are time-sensitive. A password reset that arrives 40 minutes late is useless.
So you do not need a marketing platform or a sending cluster. You need a server that accepts mail from your app, queues it safely when the destination is slow, retries on temporary failures, and signs every message. A single Postfix instance on a 1 GB VPS handles that for most small sites.
Check Port 25, Reverse DNS and Provider Rules First
Before installing anything, check whether your VPS provider blocks outbound port 25. Many budget providers block it by default, open it only after a support request, and some never open it. Test with telnet gmail-smtp-in.l.google.com 25 from your server. If it times out while port 587 works, the port is blocked. File a ticket explaining you send transactional mail from your own domain. If the provider refuses, use an SMTP relay instead of direct delivery, as covered below.
Second, set a proper hostname and reverse DNS (PTR) record: your server should identify itself as mail.yourdomain.com, and the PTR record for your IP must resolve back to that same name. Gmail treats a mismatch as a spam signal. Most VPS panels let you set the PTR record yourself; if yours does not, ask support. Our walkthrough on how to point a domain at your VPS covers the DNS side if you are starting from scratch.
Choose Your Stack: Postfix Alone or a Full Mail Suite
For outbound-only transactional mail, Postfix alone is enough. It takes messages from your app and delivers them to the destination server. Add Dovecot only if you also want to receive mail and let users read it over IMAP; most transactional setups never need it, and skipping it keeps the server simpler.
Full mail suites like Mailcow or Docker Mailserver bundle Postfix, Dovecot, spam filtering, webmail and a management panel into one install. They suit a complete mailbox server for a team, but they are overkill for a site that only sends receipts and resets, and they consume more RAM, which matters on a 1 GB VPS. Start with plain Postfix; you can add Dovecot later.
Install Postfix: Your Mail Server on a VPS
On Ubuntu 24.04, install Postfix, pick “Internet Site” when asked, and enter your mail hostname, for example mail.yourdomain.com:
sudo apt update && sudo apt install postfix -y
sudo postconf -e "myhostname = mail.yourdomain.com"
sudo postconf -e "mydomain = yourdomain.com"
sudo postconf -e "myorigin = $mydomain"
sudo systemctl restart postfix
Next, lock down who can send through it. A transactional postfix mail server should accept mail only from the local system and your app, never from the open internet:
sudo postconf -e "mynetworks = 127.0.0.0/8 [::1]/128"
sudo postconf -e "inet_interfaces = loopback-only"
sudo systemctl reload postfix
An open relay gets found by scanners within hours and used to send spam, which burns your IP reputation fast. Test that the relay is closed by trying to send from an outside machine without authentication; Postfix should reject it with a “Relay access denied” error.
Your app then connects to Postfix on localhost port 25, or on port 587 with a local account. WordPress sites usually send through a plugin like WP Mail SMTP pointed at localhost; a custom app can use any SMTP library with the host set to 127.0.0.1.
Publish SPF, DKIM and DMARC
Authentication records decide whether a mail server delivers or gets filtered. All three are DNS TXT records.
SPF lists which servers may send mail for your domain. A typical record for a single VPS looks like v=spf1 ip4:YOUR_SERVER_IP -all. The -all tells receivers to reject mail from any server not listed, which is stricter than the soft ~all many guides suggest.
DKIM adds a cryptographic signature to every outgoing message. Install OpenDKIM, generate a key pair, and publish the public key as a TXT record at selector._domainkey.yourdomain.com. Then tell Postfix to pass outgoing mail through the OpenDKIM milter so each message is signed before it leaves. Without DKIM, a receiver cannot tell whether the message was altered in transit.
DMARC tells receivers what to do when SPF or DKIM checks fail, and where to send reports. Start with a monitoring policy:
_dmarc.yourdomain.com. TXT "v=DMARC1; p=none; rua=mailto:[email protected]"
After a week or two of clean reports, move the policy to p=quarantine, then to p=reject once your mail flow is stable. A wrong SPF record under p=reject silently discards your own receipts. This same spf dkim dmarc trio is covered in our guide on how to set up a mail server on your VPS without getting blacklisted.
Test Deliverability Before You Send Anything Real
Send one test message to an address you control at Gmail and one at Outlook, then read the full headers instead of just checking the inbox. Look for spf=pass, dkim=pass and dmarc=pass in the Authentication-Results header, and fix the DNS record if any of them fails.
Also run a test through mail-tester.com, which scores your message and flags problems like a missing reverse DNS or a broken DKIM signature. Then check your IP against common blacklists: a fresh VPS IP sometimes carries a bad history from a previous tenant.
Finally, watch the Postfix queue while you test. postqueue -p shows waiting messages, and /var/log/mail.log shows why a message bounced or deferred. Our guide on how to set up email sending from your VPS without landing in spam walks through reading those bounces and fixing the common causes.
Common Failures and How to Fix Them
Mail arrives in spam. Check the three authentication passes first, then the content. A receipt full of images, URL shorteners and spammy words scores badly. Keep transactional messages mostly text, use your own domain for links, and send from a recognizable address like [email protected].
Mail never arrives and nothing bounces. The message is probably sitting in the queue. Check postqueue -p and the mail log. A message deferred for days usually means the destination is unreachable or your IP is on a blocklist that rejects silently. If the IP is listed, request delisting and ask your provider for a clean IP.
Keep the Server Healthy Over Time
A mail server is not set-and-forget. Watch three things on a regular schedule. First, read the DMARC reports at your reporting address; a sudden spike in failures means a DNS record changed or someone is spoofing your domain. Second, check the queue size and log volume weekly: a growing queue means deliveries are failing, and unchecked logs will fill a small VPS disk, so set up log rotation and disk alerts. Third, keep Postfix and OpenDKIM updated, since mail software has a long history of security fixes.
Keep transactional mail separate from bulk or marketing mail. If you later need newsletters, send them from a different subdomain or a dedicated service; one bad campaign can damage the reputation your password resets depend on. If your project only needs incoming mail forwarding, our guide on how to set up email forwarding on your VPS with a free service is a lighter alternative.
When Self-Hosting Stops Making Sense
Self-hosting wins on control and cost, but it has a clear limit. If your provider will not unblock port 25, if you send high volumes needing dedicated IP warm-up, or if nobody has time to read DMARC reports and handle a blacklist delisting, a managed relay is the better choice. Services like Amazon SES, Mailgun, SendGrid and Postmark handle the reputation work for you, and their entry tiers are cheap for a small project. Prices change often, so check official pricing before committing.
Start with the pre-flight checks, get the three authentication records right, and test with real inboxes before switching your app over. A mail server that passes its tests on day one and gets watched once a week keeps delivering the messages your users never notice.