Skip to content

Lesson 2 of 9 · 26m

Submission Architecture, TLS, Ports, and Queues That Survive Reality

Design outbound mail paths with authenticated submission, correct TLS expectations, durable queues, backoff, idempotency, and separate traffic classes.

Email infrastructure fails quietly long before it fails loudly. A web request either returns or times out; an email can be accepted into a queue, deferred for eighteen hours, throttled by a receiver, retried in the wrong order, then delivered after the user already reset their password a second time. If you design email as a synchronous side effect of HTTP requests, production will eventually teach you otherwise.

Separate submission from transport

Port history causes endless confusion:

25    server-to-server SMTP relay, often opportunistic TLS
587   authenticated message submission, STARTTLS expected
465   implicit TLS submission, legacy standardized again
2525  provider convenience port, not magic

Your application should normally submit to a controlled relay or provider over 587 with STARTTLS or 465 with implicit TLS. It should not connect directly to arbitrary recipient MX hosts. The local or provider MTA handles DNS lookup, connection concurrency, queueing, retry policy, bounce reception, and rate shaping.

# application boundary: enqueue work, do not synchronously "send internet mail"
send_mail_job.enqueue(
    template="password_reset",
    recipient="user@example.net",
    idempotency_key=f"reset:{user_id}:{token_id}",
)

The queue is not optional infrastructure polish. It is what prevents a receiver slowdown from turning into web latency, thread exhaustion, and duplicate user-visible actions.

TLS means different things at different layers

Submission TLS protects the path from application to relay. End-to-end encryption is not implied. Server-to-server SMTP commonly uses opportunistic TLS: the sending server attempts STARTTLS if the receiver advertises it. Unless MTA-STS or DANE is involved, attackers in path may try to downgrade or intercept that negotiation.

Inspect what your MTA actually negotiated:

postqueue -p
postcat -q 4F2C81 | sed -n '/^regular_header/,$p' | head -40
grep 'TLS' /var/log/mail.log | tail -20

A provider dashboard saying "TLS enabled" usually describes only one hop. That is fine, but do not market it as end-to-end encryption.

Backoff and traffic classes are deliverability controls

Transactional mail, bulk marketing, password resets, and inbound replies have different urgency and reputation profiles. Separate them by sending identity and often by IP or provider stream:

password resets       low volume, urgent, zero marketing content
transactional notices moderate volume, expected by user
bulk marketing        high volume, complaints drive reputation
inbound parsing       automated replies, high loop risk

Retry policy matters. Respect 4xx responses and implement exponential backoff with jitter. Cap total retry age according to message usefulness. A password reset deferred for six hours is often worse than a clean failure because the token is stale by the time it arrives.

Field notes

  • Never put sendmail in the critical path of a user request unless the only action is enqueueing locally.
  • Receiver throttling is backpressure. Spreading it blindly across more IPs is snowshoeing and damages reputation.
  • Clock correctness matters; TLS validation and signed tokens both depend on it.
  • Keep mail queues encrypted and access-controlled. Queued mail often contains reset links and personal data.
  • Test provider failover with a small canary stream, not during a full outage.

Was this lesson helpful?

Sign in to rate