Outbound mail: nodemailer + Liquid templates + DB outbox, structured for later extraction
- Deciders: Julian Bäume
- Date: 2026-07-08
Status
Accepted
Context
ADR-0010 makes outbound mail a core dependency of Appointment Booking: iMIP REQUEST/CANCEL messages carry the calendar integration, and the booker's confirmation (with the manage link) and cancellation notices are mails this service sends itself. The spec requires localized mails (booker mails in the booking's stored locale, owner mails in the owner's App Suite locale) and per-deployment customization of mail content — our customers white-label everything.
Deployments authenticate against the mail stack (Postfix submission with Dovecot SASL) either with plain credentials or with OIDC access tokens (SASL XOAUTH2/OAUTHBEARER, which Dovecot validates via RFC 7662 introspection or local JWT validation).
Separately, there is an org-level ambition to replace the legacy Java-templated mails with a shared mail capability, with MJML floated as its templating technology. That decision belongs to the teams collaboratively owning the stack and is not made here — but this service ships the stack's first templated-mail implementation, so whatever it does must not pre-empt that decision (the comparative templating research is being brought to that group separately).
Decision
- Transport: nodemailer. SMTP with pooled connections;
PLAIN/LOGINfor plain credentials, built-inXOAUTH2, andOAUTHBEARERvia nodemailer'scustomAuthhook. OIDC tokens come from aclient_credentialsgrant against the configured token endpoint, cached until shortly before expiry. Connection and behavior settings live in the hot-reloadedconfig.yaml(mailsection); secrets come from the environment (MAIL_PASS,MAIL_CLIENT_SECRET) like the DB credentials. - iMIP payloads: ical-generator, attached through nodemailer's
icalEventoption (which produces thetext/calendar; method=…+application/icsMIME structure calendar clients require). Events carry the deterministic booking-scopedUIDfrom ADR-0010 and are emitted with UTC times, avoidingVTIMEZONEgeneration. - Templates: LiquidJS over plain HTML plus separate plain-text templates. Liquid is sandboxed by design (no code execution, output-escaped), which is what makes operator-editable templates safe. Each mail type is three files per locale —
<template>.<locale>.subject.liquid,.html.liquid,.txt.liquid— resolved with a locale fallback chain (exact → base language →en). Defaults ship in the image (src/mail/templates/); operators override individual files under$CONFIG_PATH/mail-templates/. Templates are parsed and validated at (re)load time, never at send time: a broken override logs an error and the last known good (or shipped) version keeps serving. - Delivery: a
mail_outboxtable, not fire-and-forget. Domain code enqueues mail in the same transaction as the booking mutation; a worker (same idempotent, replica-safe pattern as the poll cleanup job) claims due rows, renders, sends, and retries with exponential backoff until a bounded attempt count, then marks the row failed. This keeps ADR-0010's "slot blocked immediately, calendar delivery is asynchronous decoration" literally true and survives SMTP outages. Outcomes are counted inbooking_mail_total{template, operation}. - The module is the embryo of a shared mail service, deliberately. Domain code uses one narrow, remote-shaped interface —
enqueueMail({ template, locale, to, data, ical? })with a JSON-serializable payload — and never touches transport or rendering. Template resolution is keyed(template, locale)with room for a brand dimension. MJML is deliberately absent from the runtime contract: if the org round adopts it, shipped defaults can be re-authored in MJML (at most a devDependency compiling at build time) without changing the override mechanism, the data contracts, or this ADR's architecture; a future mail service can accept raw-HTML and MJML templates side by side.
Consequences
Positive
- One mail stack covers both ADR-0010 gaps (calendar delivery, booker mails) with three small, actively maintained, MIT(-0)-licensed dependencies and no framework coupling.
- Operators customize mails per deployment by dropping files into the existing config volume — same mental model as
config.yaml, no redeploy, no send-time failure mode. - The transactional outbox makes mail delivery crash-safe and horizontally safe (2 replicas) without new infrastructure.
- The markup-dialect decision stays genuinely open for the org-level round; nothing here needs revisiting if it lands on MJML (or against it).
Negative / constraints
- The outbox adds a table, a worker, and delivery latency up to one worker interval.
- Mails render from hand-written single-column HTML — fine for our transactional mails, but rich branded layouts must wait for the org templating decision (or arrive as operator-provided HTML overrides).
- Localized defaults must be maintained per locale in this repo until a shared mail service takes that over.
OAUTHBEARERsupport rides on nodemailer'scustomAuthextension point rather than a first-class mechanism; the implementation carries a small amount of SASL encoding code and needs an integration test against Dovecot.

