Dev.to Security πŸ” Cybersecurity πŸ‘ 0 πŸ“– 3 min read

Transactional email that lands in the inbox: a developer checklist

Password resets, receipts, magic links, invites. When these land in spam, users don't complain about deliverability. They just leave. Here is the checklist I use before shipping transactional email in any app. Most of it

Password resets, receipts, magic links, invites. When these land in spam, users don't complain about deliverability. They just leave. Here is the checklist I use before shipping transactional email in any app. Most of it is DNS and a few lines of code.

1. Send from a subdomain

Use something like mail.yourapp.com or notify.yourapp.com instead of the root domain. If a marketing blast goes badly, the reputation damage stays on that subdomain, and your team's normal Google Workspace or Outlook mail keeps working.

Keep transactional and marketing mail on separate streams (different subdomains or at least different IPs/streams at your provider). A password reset should never queue behind a newsletter or inherit its complaint rate.

2. SPF, DKIM and DMARC: all three, not one

SPF: one TXT record per hostname. Two SPF records is a permanent error, and receivers treat it as no SPF at all.

mail.yourapp.com.  TXT  "v=spf1 include:_spf.yourprovider.com ~all"

SPF allows at most 10 DNS lookups. Every include: counts, including nested ones. Check with any SPF lookup tool before you add a fifth vendor.

DKIM: use 2048-bit keys. Your provider gives you the selector records (usually CNAMEs) to publish. DKIM is what survives forwarding, so it matters more than SPF in practice.

DMARC: start in monitor mode with reports, then tighten.

_dmarc.yourapp.com.  TXT  "v=DMARC1; p=none; rua=mailto:[email protected]"

Read the aggregate reports for a couple of weeks, fix anything legitimate that fails alignment, then move to p=quarantine and later p=reject.

Since February 2024, Gmail and Yahoo require bulk senders (roughly 5,000+ messages a day to their users) to have SPF, DKIM and DMARC in place, support one-click unsubscribe on marketing mail, and keep spam complaints under 0.3%. Small apps should do the same anyway; it is the baseline now.

3. Treat bounces and complaints as data, not noise

  • Hard bounce (address does not exist): suppress it immediately and permanently. Retrying hurts your reputation.
  • Soft bounce (mailbox full, temporary failure): retry with backoff, then suppress after a few failures.
  • Complaint (user hit "report spam"): suppress for marketing at once. Look at what you sent them.

Keep one suppression list that every sending path checks: transactional, marketing and anything a teammate scripts on a Friday afternoon.

4. Make sends idempotent

Your job queue will retry. Your HTTP client will time out after the provider already accepted the message. Without an idempotency key, users get three password-reset emails.

await sendEmail({
  to: user.email,
  template: "password-reset",
  data: { link },
  idempotencyKey: `reset:${user.id}:${token.id}`,
});

If your provider doesn't support idempotency keys, store a "sent" flag keyed the same way before you call it.

5. Verify webhooks properly

Delivery, bounce and open events usually arrive by webhook. Verify the signature, use a constant-time compare, and reject old timestamps to stop replays.

import crypto from "node:crypto";

export function verifyWebhook(rawBody, signature, timestamp, secret) {
  const ageSeconds = Math.abs(Date.now() / 1000 - Number(timestamp));
  if (ageSeconds > 300) return false; // replay window: 5 minutes

  const expected = crypto
    .createHmac("sha256", secret)
    .update(`${timestamp}.${rawBody}`)
    .digest("hex");

  const a = Buffer.from(expected);
  const b = Buffer.from(signature);
  return a.length === b.length && crypto.timingSafeEqual(a, b);
}

Two common bugs: verifying the parsed-and-re-serialized JSON instead of the raw body, and comparing with ===. Also dedupe events by their ID, because providers deliver webhooks at least once.

6. Small things that add up

  • Always include a plain-text part.
  • Use a real reply-to address someone reads.
  • Add List-Unsubscribe and List-Unsubscribe-Post: List-Unsubscribe=One-Click headers to anything that isn't strictly transactional.
  • Don't put a URL shortener in a password-reset email.
  • Send a test to Gmail, Outlook and Yahoo accounts and check "show original" for spf=pass dkim=pass dmarc=pass.

Where Elma fits

I'm building Elma.sh because I kept wiring this same checklist together across three tools. It sends transactional email, campaigns and automations from one API and dashboard, with a single contact graph so suppressions and segments agree everywhere, plus templates, delivery tracking, bounce handling and HMAC-signed webhooks. There is a free plan with 1,000 emails a month, no card needed.

But the checklist above works with any provider. Do steps 2 and 3 first.

Shubham Nigam, Founder, Elma.sh

πŸ“° Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.