Lesson 11 of 14 · 15m
Mail That Lands in Inboxes
Port 25 is blocked and your IP has no reputation — submission relays, SPF/DKIM/DMARC, and why running your own MX is a reputation job.
Your app's first signup email hits a wall your firewall didn't build. Outbound TCP/25 is blocked by default at most cloud providers — DigitalOcean blocks it on new accounts, Hetzner holds it closed until you've paid an invoice or two and asked, OVH gates it on some products and regions. And even if your provider opens it, the receiving end is the harder problem: a fresh VPS IP has zero reputation, no PTR record matching your HELO, no SPF, no DKIM, no DMARC — Gmail files it as spam before your user ever sees it.
The mechanism that actually delivers
App → submission port → relay. Your code talks SMTP on 587 (STARTTLS) or 465 (implicit TLS) — or plain HTTPS to the provider's API — to a transactional relay: Postmark, Amazon SES, Resend, Brevo, Mailgun. The relay holds IP reputation, signs DKIM, and has spent years earning Gmail's trust. You send through credentials stored in your secrets discipline (env_file/secrets from last lesson — SMTP passwords are secrets like any other).
Then the three DNS records that make it work:
- SPF — a TXT saying who's allowed to send for your domain:
v=spf1 include:_spf.provider.example ~all. One SPF record per domain — multiplev=spf1records is a parse failure, not redundancy. - DKIM — the provider generates a key pair, you publish the public half as a TXT or CNAME at their selector (
something._domainkey.example.com), they sign every outgoing message with the private half. - DMARC —
_dmarc.example.comTXT startingv=DMARC1; p=none; rua=mailto:dmarc@example.com— collect reports, verify alignment, then graduatep=quarantine→p=rejectonce the reports show only your real senders.
Since February 2024, Gmail requires SPF + DKIM + DMARC for bulk senders — and in practice the trio is the admission price for anyone's mail landing in an inbox, not a bulk-only rule. mail-tester.com gives you a scored test message; fix what it flags.
Why "run my own mail server" loses here
The wrong mental model: "I self-host everything; mail is just another service." The software is the easy part — Stalwart, Postfix, or Mailcow all run fine. The hard part is the world's distrust of fresh IP space: your /32 comes with inherited reputation, often a spot on RBLs from the previous tenant's spam, a PTR that must exactly match your HELO hostname, and an inbox-warming curve measured in weeks. Deliverability is a reputation operation, not a software deployment. Running your own MX to receive mail is a separate question with its own costs (storage, spam filtering, availability); for an app that only needs to send, self-hosting outbound is sovereignty purchased with ongoing ops work.
The honest tradeoff: a relay is an external dependency that costs per-mail and sees message bodies. For one app's transactional volume — signups, resets, receipts — it wins on operator time by months over babysitting IP reputation. If the privacy cost is unacceptable, the real alternative is dedicating a host to mail with a warmed, monitored IP — a job, not a checkbox.
Field notes
- Send app mail from
noreply@(or a dedicated subdomain likemail.example.com) — subdomain sender separation keeps your apex's reputation clean. - Set the
PTR/rDNS record if you ever do send direct — HELO hostname, PTR, and SPF alignment are the first checks receivers run. - Read DMARC
ruareports before tightening policy —p=rejecton a domain with a forgotten legit sender silently destroys real mail. - Test with a real Gmail inbox, not just logs: "sent" in your app means SMTP accepted it, nothing more.
- Keep the relay credentials rotatable — they're in env_file/secrets like every other credential, and a leaked SMTP password is a phishing cannon pointed at your users.
Was this lesson helpful?
Keep reading
Related articles from the SudoSecurity blog.
Self-Hosting Vaultwarden Without Trusting the Defaults
Vaultwarden gives you a Bitwarden-compatible password server in one container and about ten minutes. The defaults that make that possible leave org creation open, audit logging off, accounts on PBKDF2, and a rate limiter that trusts a header anyone can set.
What You Can Self-Host on Oracle Cloud Free Tier (2026)
What actually fits on Oracle Cloud free tier after the June 2026 cut: Ghost, Vaultwarden, Syncthing, monitoring, and a small AI model, sized in real RAM.
The Complete Self-Hosted AI Stack for 2026
Building a local AI server is more than installing Ollama. This guide builds a full production AI stack with Open WebUI, LiteLLM, Qdrant, Traefik, and Langfuse — what each component does, why it's needed, and three complete Docker Compose configurations for beginners, power users, and small teams.
Self-Host OpenClaw: VPS Setup to Production (2026)
Self-host OpenClaw from zero to production. Server provisioning, SSH lockdown, Docker, reverse proxy, Fail2ban, performance tuning, and full backup strategy in one guide.