Storefront has been decoupled into micro-frontends with a dedicated commerce app and shared shell.

Read the architecture guide →

ADR-003: Keep email delivery behind a MailKit SMTP provider boundary

Notification submits MIME messages through MailKit over SMTP, using MailPit in development and a configured provider elsewhere without relying on SendGrid's HTTP API.

November 1, 2026AcceptedIntegration

1. Context & Problem

BookWorm needs a practical way to send emails across different environments—allowing developers to test email formatting and flows locally without sending real messages to customers, while using a production mail service in live environments. Coupling order workflows directly to a specific vendor’s proprietary web API would make switching providers harder and complicate local testing. In addition, external mail submission can time out or fail independently of BookWorm’s internal saved notification state.

2. Business Value

  • Safe, realistic local testing: Engineers can verify full email rendering and sending workflows in development using a local test inbox without risking accidental customer emails or incurring provider costs.
  • Vendor flexibility: Using a standard email transport protocol keeps order commands and message rendering isolated from any single provider’s proprietary API.
  • Controlled resilience: Built-in timeouts, retries, and circuit breaking protect the service from hanging indefinitely when an external mail server becomes slow or unresponsive.
  • Clear accountability: Finance owns order meaning, Notification owns formatting and submission policy, and the external provider owns its mail delivery network.

3. How It Works

  1. Environment-aware routing: In development environments, emails are routed to a local test mail catcher; outside development, they are sent to the configured external mail provider.
  2. Standardized handoff: Notification prepares the formatted message and passes it through a standard mail-transport boundary rather than calling vendor-specific web endpoints.
  3. Protected submission attempt: The actual message send is wrapped in a resilience policy with timeouts, jittered retries, and a circuit breaker. Connection setup and optional login occur before the send step, and disconnection occurs afterward.
  4. Honest failure reporting: Any error during connection, sending, or disconnection is logged and propagated rather than falsely marking the email as sent. If a failure leaves the outcome uncertain, the record remains eligible for a later retry attempt.

4. Trade-offs & Lessons Learned

  • Per-attempt resilience is not a lifetime cap: The retry and circuit-breaker safeguards bound retries within a single send attempt only; they do not limit how many times future scheduled maintenance runs can re-attempt an unsent record.
  • Broad exception handling without permanent failure classification: Current retry and circuit-breaker rules treat exceptions broadly and do not automatically move permanently undeliverable addresses into a separate terminal failure state.
  • Connection lifecycle sits outside the send pipeline: Because connecting, authenticating, and disconnecting occur outside the wrapped send step, timeouts and retries do not cover the entire connection lifecycle equally.
  • Ambiguous failures can still cause duplicates: If a provider accepts a message right before a disconnect error or a failed status update, a subsequent retry may submit the email again. Provider acceptance remains a submission result, not a delivery receipt.
  • Provider switches still require operational validation: Although order contracts stay unchanged when switching providers, teams must still validate endpoint details, authentication credentials, encryption settings, and provider capabilities.
  • Alternatives rejected:
    • Calling a provider’s proprietary HTTP mail API: Rejected to avoid vendor-specific HTTP contract coupling; the active path uses standard mail transport rather than SendGrid’s HTTP API.
    • Hard-coding a production provider into order handlers: Rejected because it couples Finance workflows directly to provider configuration.
    • Marking an email sent upon provider connection: Rejected because opening a connection does not confirm a message was submitted.

5. Technical Reference

  • Status & Context: accepted (2026-11-01). Preserves the external-provider boundary from ADR-001: Keep notification ownership inside BookWormDecision Recordv1.0.0ADR-001: Keep notification ownership inside BookWormBookWorm treats SendGrid as an external delivery provider while the Notification System owns notification state, busines...Ownerplatform-engineering-teamOpen docs, while documenting the active MailKit SMTP path and the absence of persisted provider responses (the older record remains unchanged).
  • Boundaries & Abstractions:
    • Notification SystemSystemv1.0.0Notification SystemInternal platform system that consumes order commands, renders email templates, and submits messages over SMTP. Ownerplatform-engineering-teamDiagramOpen docs owns rendering, email outbox state, and submission policy.
    • ISender resolves to the email outbox wrapper; IEmailSender performs MailKit SMTP submission of the rendered MIME message.
    • Uses MailPit in development and a configured SMTP provider elsewhere (e.g., SendGridSystemv1.0.0SendGridExternal email delivery platform used by BookWorm to submit rendered transactional emails over authenticated SMTP. Ownerplatform-engineering-teamDiagramOpen docs as an external SMTP endpoint; does not invoke SendGrid’s HTTP Mail Send API or the cataloged SendGrid API service).
  • Resilience Pipeline (SendAsync):
    • Wraps SendAsync with a circuit breaker, exponential retry backoff with jitter, and a 30-second timeout.
    • Connection and optional authentication occur before the pipeline; disconnect occurs afterward and can fail independently of SendAsync.
    • Failures are logged and propagated, not converted into sent state; provider responses and final delivery statuses are not persisted.
  • Operational Validation on Provider Change: Validate SMTP endpoint, authentication, TLS behavior, and delivery configuration even though Finance’s message contracts remain unchanged.