Skip to content

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 — multiple v=spf1 records 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.com TXT starting v=DMARC1; p=none; rua=mailto:dmarc@example.com — collect reports, verify alignment, then graduate p=quarantine → p=reject once 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 like mail.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 rua reports before tightening policy — p=reject on 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?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.