Prompt
I'm building a mobile app backend and need email delivery infrastructure
Latest observation
Sure — for a mobile app backend, email delivery infrastructure usually means more than just “send emails.” You want:
- Reliable outbound delivery
- Authentication and deliverability
- Tracking and observability
- Queueing/retries
- Templates and localization
- Security and compliance
Recommended architecture
1) Use a dedicated email provider
Common options:
- AWS SES — best for cost and scalability
- SendGrid — good developer experience and templates
- Mailgun — strong API and inbound handling
- Postmark — excellent for transactional emails
- Brevo (Sendinblue) — good all-in-one option
For a mobile app backend, I’d usually recommend:
- Postmark for transactional-only apps
- AWS SES if you want low cost and are comfortable with more setup
- SendGrid if you want easier tooling and dashboards
2) Separate transactional and marketing emails
Keep these in different streams/domains:
- Transactional: password reset, verification, receipts, alerts
- Marketing: newsletters, promos, onboarding campaigns
This helps protect deliverability. If marketing emails get complaints, your critical transactional mail is less affected.
3) Use a dedicated sending domain or subdomain
Examples:
mail.yourapp.comnotify.yourapp.commg.yourapp.com
Avoid sending from your root domain if possible. This isolates reputation and reduces risk.
4) Set up email authentication
You should configure:
- SPF
- DKIM
- DMARC
These are essential for deliverability and spoofing protection.
Typical setup:
- SPF authorizes your provider to send on your behalf
- DKIM signs messages cryptographically
- DMARC tells receivers how to handle failed authentication
5) Implement a queue-based sending system
Do not send emails directly in your request/response cycle.
Better flow:
- App/backend triggers email event
- Event goes into queue
- Worker sends through provider
- Retries on transient failures
- Logs success/failure
Use something like:
- SQS + worker
- RabbitMQ
- Redis queue / BullMQ
- Celery
- Sidekiq
- Kafka if you already have it
6) Track delivery events
Enable webhooks from your provider for:
- Delivered
- Bounced
- Complained
- Deferred
- Opened/clicked if needed
Store these in your backend for:
- suppression lists
- analytics
- account health monitoring
- alerting on issues
7) Maintain suppression and bounce handling
Automatically suppress:
- hard bounces
- spam complaints
- unsubscribes
- invalid addresses
This prevents repeated sending to bad addresses and protects your sender reputation.
8) Template system
Use templates for:
- verification emails
- password resets
- welcome emails
- receipts
- security alerts
Best practice:
- keep copy versioned
- support localization
- include plain-text fallback
- use variable substitution safely
9) Security considerations
- Never expose your provider API key in the app
- Send only from your backend
- Rate-limit sensitive emails like verification and password reset
- Add anti-abuse controls for account creation and email flooding
- Use signed, expiring links for actions like verification/reset
10) Monitoring and alerting
Monitor:
- send rate
- bounce rate
- complaint rate
- provider errors
- queue backlog
- webhook failures
Set alerts for:
- spike in bounces
- queue buildup
- SMTP/API failures
- DMARC failures if you track them
Example backend flow for verification email
- User signs up in mobile app
- Backend creates account with
email_verified = false - Backend generates signed token
- Backend publishes
send_verification_emailjob - Worker sends via provider
- Provider returns message ID
- Webhook updates status later
- User clicks verification link
- Backend verifies token and marks email verified
Suggested minimal production stack
If you want something practical and fast to launch:
- Provider: Postmark or AWS SES
- Queue: SQS, BullMQ, or Sidekiq
- Templates: provider-managed or app-managed templates
- Webhooks: for bounce/complaint/delivery events
- Domain:
notify.yourapp.com - Auth: SPF + DKIM + DMARC
- Monitoring: CloudWatch, Datadog, or similar
If you want, I can help you with one of these next:
- Choose the best provider for your use case
- Design the backend email architecture
- Set up SPF/DKIM/DMARC
- Write code examples in Node.js, Python, Go, or Java
- Design a transactional email service for your app
If you tell me your stack and expected email volume, I can recommend a concrete setup.