Prompt
How do I send password reset and verification emails reliably at scale?
Latest observation
To send password reset and verification emails reliably at scale, optimize for deliverability, security, and operational robustness. Here’s a practical checklist.
1) Use a dedicated transactional email provider
For password resets and verification, use a provider built for transactional delivery, such as:
- Amazon SES
- SendGrid
- Mailgun
- Postmark
- SparkPost
Prefer a separate transactional stream/domain from marketing email.
2) Authenticate your domain properly
Set up:
- SPF
- DKIM
- DMARC
Also:
- Use a custom sending domain, e.g.
mail.example.com - Align the visible
From:domain with your authenticated domain - Make sure bounce/return-path handling is configured
Without these, emails are more likely to land in spam or be rejected.
3) Separate transactional and marketing traffic
Do not mix password reset emails with bulk campaigns on the same:
- IP pool
- subdomain
- sending reputation
This protects critical auth emails from reputation damage caused by marketing sends.
4) Design for high deliverability
Best practices:
- Keep subject lines clear and non-spammy
- Avoid heavy HTML, large images, and URL shorteners
- Include a plain-text version
- Use consistent “From” names and addresses
- Keep links on your own domain
- Avoid suspicious wording like “urgent”, “free”, “click now” unless appropriate
5) Make reset and verification links secure
For the app side:
- Generate single-use tokens
- Make tokens short-lived (often 10–30 minutes for resets, somewhat longer for verification if needed)
- Store hashed tokens server-side if possible
- Invalidate old tokens when issuing a new one
- Bind tokens to the intended account and purpose
- Rate-limit requests per account, IP, and device
Never put sensitive data in the email link itself.
6) Build idempotent, retry-safe sending
At scale, duplicate sends happen unless you plan for them.
Use:
- A queue/job system for email delivery
- Idempotency keys per email event
- Retries with exponential backoff
- Dead-letter queues for failures
- De-duplication logic in the sender or worker
If a request times out after enqueueing, you should still avoid sending twice.
7) Decouple request handling from sending
Do not send the email synchronously in the user request path.
Instead:
- User requests reset/verification
- API validates request and creates token
- API enqueues an email job
- Worker sends email asynchronously
- API returns immediately
This improves latency and resilience.
8) Handle bounces, complaints, and suppression
Set up provider webhooks for:
- Hard bounces
- Soft bounces
- Complaints
- Deliveries
- Blocks
Then:
- Suppress bad addresses
- Investigate complaint spikes
- Monitor deliverability by domain/provider
For verification/reset emails, make sure suppression logic does not block critical messages incorrectly due to transient issues, but do respect hard bounces and complaints.
9) Rate-limit abuse
Password reset endpoints are a target for abuse and email bombing.
Protect with:
- Per-IP and per-account rate limits
- CAPTCHA or challenge after suspicious patterns
- Detection of repeated requests to the same address
- Device/session anomaly checks
- Logging and alerting on spikes
Also avoid revealing whether an email exists:
- Respond generically: “If an account exists, we sent an email.”
10) Support link expiration and re-issue flows
Users often click old links or request multiple emails.
Implement:
- Clear expiration messaging
- “Resend email” flow with cooldown
- Automatic invalidation of prior reset tokens on new request
- Friendly error pages for expired/used tokens
11) Monitor the right metrics
Track:
- Delivery rate
- Bounce rate
- Complaint rate
- Open/click rate, if useful
- Time-to-delivery
- Queue depth and send latency
- Provider error rates
- Domain-specific deliverability issues
Set alerts for:
- Sudden bounce spikes
- Complaint spikes
- Token generation/sending failures
- Elevated queue age
12) Test across major mailbox providers
Test with:
- Gmail
- Outlook/Hotmail
- Yahoo
- Apple Mail / iCloud
Check:
- Inbox placement
- Spam placement
- Link rendering
- Mobile display
- Dark mode compatibility if relevant
13) Consider fallback strategies
For critical flows:
- Resend through a secondary provider if the primary is degraded
- Cache provider response states carefully
- Use circuit breakers to avoid cascading failures
- Keep your sending logic provider-agnostic where possible
14) Operational security and compliance
- Protect tokens in logs
- Avoid logging full reset URLs
- Use HTTPS only
- Ensure links are not guessable
- Minimize PII in emails
- Follow relevant rules like CAN-SPAM, GDPR, and local privacy laws
- Provide account recovery and support paths for users who can’t access email
A good reference architecture
- API service generates a token and enqueues an email job
- Queue (e.g. SQS, RabbitMQ, Kafka) buffers load
- Email worker sends via transactional provider
- Webhook handler processes bounce/complaint events
- Monitoring/alerting watches delivery health
- Fraud/rate-limit layer prevents abuse
Minimal implementation pattern
- Generate random token with strong entropy
- Store token hash + expiry + user ID + purpose
- Enqueue email job with token link
- Send email via transactional provider
- On click, validate token, expiry, purpose, and single-use status
- Mark token as used and rotate credentials if needed
If you want, I can also give you:
- a production-ready architecture diagram,
- a sample database schema for reset tokens, or
- code examples for Node.js, Python, or Go.