Email infrastructure guide

Email API with Node.js

A server-side pattern for sending transactional email from Node.js without leaking API keys.

Node.js applications should keep email sending behind a server-side module or job worker. The module receives a validated message request, calls the email API, and persists the provider response for observability.

What this means in practice

  • Server-only API credentials
  • Input validation before sends
  • Timeout and retry policy
  • Stored message identifiers for support and audit

Implementation checklist

  1. Read the API key from a server environment variable.
  2. Validate sender, recipient, subject, and content fields.
  3. Call the email API from a service module or queue worker.
  4. Store the returned message ID with the product event.
  5. Retry only failures that are known to be transient.

Questions teams ask

Can I call an email API from browser JavaScript?

Do not expose a sending API key in browser code. Send through your Node.js backend instead.

Should email sending block a web request?

For critical actions it can, but queues are often better for retries and resilience.