Skip to content

feat: Brevo and Amazon SES accounts, language versions and provider opens/clicks for provider templates - #28

Merged
Schero94 merged 4 commits into
mainfrom
feat/providers-brevo-ses
Nov 19, 2026
Merged

Schero94 merged 4 commits into
mainfrom
feat/providers-brevo-ses

Conversation

@Schero94

@Schero94 Schero94 commented Nov 18, 2026 •

Copy link
Copy Markdown
Owner

Draft, waiting for the live run (npm run test:live with Brevo and Amazon SES credentials in ~/.config/magic-mail-live/.env), like #20 and #23. Stacked on #20 (feat/provider-templates), which is stacked on #23; this PR retargets automatically when #20 is merged. Do not merge before a passing live run is recorded in docs/acceptance/2026-11-18-brevo-ses.md.

What this adds

1. Brevo account type (server/src/providers/brevo.js)

  • Send via POST /v3/smtp/email (api-key header): sender, to/cc/bcc (deduplicated), one reply-to (several are refused with 400), html/text, attachments (no cid, Brevo's extension list), filtered headers. Correlation: X-Mailin-custom: magicmail_id=<log id>. Caller X-Sib-*/X-Mailin-* headers are dropped. Size limit 20 MB.
  • Wizard step with Check connection (GET /v3/account, no email sent, no personal data returned) and actionable hints (BREVO_INVALID_KEY, BREVO_IP_NOT_AUTHORIZED, BREVO_ACCOUNT_UNDER_VALIDATION, BREVO_SENDER_NOT_VERIFIED, BREVO_NO_CREDITS, …).
  • Webhooks: Brevo has no payload signature, so MagicMail creates a 256-bit random token per account (encrypted, masked everywhere). POST /magic-mail/accounts/:id/webhook-token (manage, browser sessions only, admin API tokens get 403, audit-logged, rate limited) shows or rotates it. Accepted as Authorization: Bearer or X-Magic-Mail-Webhook-Token, compared in constant time.
  • Templates: list/get with paging; inactive templates show as unpublished; send with templateId + params (your data; a Brevo template writes {{ params.name }}, the UI says so and lists variables without params.).
  • Brevo has a single API host (no EU/region option exists).

2. Amazon SES v2 (server/src/providers/ses.js, utils/aws-sigv4.js, utils/sns-verify.js)

  • No AWS SDK (@aws-sdk/client-sesv2 would add 24 packages / ~16 MB and an instance-metadata credential chain). Own SigV4 (~200 lines, node:crypto), tested against all 38 cases of the official AWS SigV4 test suite.
  • Send Content.Simple (headers ≤ 15, attachments, RFC 2047 for non-ASCII) or Content.Template (TemplateData), EmailTags (magicmail_id), configuration set, ConfigurationOverrides.Tracking; limits 50 recipients, 40 MB, 256 KiB template data.
  • Wizard: region, IAM access key or server environment credentials (AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY/AWS_SESSION_TOKEN; no IMDS/ECS fetch), configuration set, SNS topic ARN; Check connection (GetAccount: sandbox, sending, quota).
  • Webhook: SES event destination → SNS → HTTPS. TopicArn must match, certificate only from https://sns.<topic-region>.amazonaws.com/SimpleNotificationService-*.pem (no redirects, 16 KB cap, cached), SignatureVersion 1/2 verified, SubscriptionConfirmation confirmed only on the same host pattern, replays ignored.

3. Language versions (per-locale provider-template mapping)

  • PUT /provider-templates/:key/settings { locales: { de: 'brevo:welcome-de' } }; the dialog adds a version in 4 interactions (type language, pick synced template, saved on pick). Same provider only, no chains, no typed ids.
  • send({ providerTemplate, locale }): exact tag → language → default; without locale, the recipient user's stored locale (only when the users-permissions user type has a locale attribute). Unusable versions are skipped. Core mails use the user's locale and send it as meta.locale; test sends use language or the admin's interface language. The log records key, sent version and locale.

4. Opens and clicks for provider-rendered bodies

  • New setting Count provider opens and clicks (off; only visible with a SendGrid/Mailgun/Brevo/SES account). Provider-template sends then ask the provider to track (SendGrid tracking_settings, Mailgun o:tracking-opens=yes/o:tracking-clicks=htmlonly, SES tracking override; Brevo is account-level) and flag the log providerTracking.
  • SendGrid open/click, Mailgun opened/clicked, Brevo opened/click and SES Open/Click events increase the counters only for those logs (no double counting with MagicMail's pixel), de-duplicated by event id; clicked URLs stored as origin + path only, sensitive links dropped, no provider IP/UA stored.

Scaffold: server/src/providers/index.js defines the adapter interface; SendGrid, Mailgun, SMTP and OAuth paths are untouched.

Old features

Golden payload tests for SendGrid, Mailgun and SMTP pass unchanged (byte-identical requests). Inventory tests updated for the new routes (/accounts/:id/check, /accounts/:id/webhook-token, /webhooks/brevo/:id, /webhooks/ses/:id). PUT /provider-templates/:key/settings: fallbackTemplateReferenceId is now optional (one of it or locales required) — additive. Minor release.

Tests and gates (Node 22.23.1, final commit)

  • npm test (after rebasing onto feat: provider templates for SendGrid and Mailgun #20 at 882a86a): 915 tests, 912 pass, 0 fail, 3 skipped (PostgreSQL multi-process, as before). New suites: brevo-adapter 26, brevo-contract 11, brevo-integration 19, aws-sigv4 41, ses-adapter 22, ses-contract 6, ses-integration 12, sns-verify 13, provider-locales-tracking 20, admin-brevo-ses-ui 6, live-env-providers 2 (LIVE_PROVIDERS now also accepts brevo, ses; the SendGrid/Mailgun suites skip instead of failing when only those are selected).
  • lint, format:check, build, verify, verify:runtime: clean. npm audit --omit=dev: 0. No new dependency.
  • Pinned specs: Brevo OpenAPI email-api.json (sha256 d56adf66…) and accounts-and-settings.json (e9f90329…) from developers.brevo.com; SES v2 Smithy model from aws/api-models-aws@9f371492 (f34aeda9…); SigV4 vectors from awslabs/aws-c-auth@cf69fb7e.

Browser acceptance

Isolated Strapi 5.62.0 host (127.0.0.1:1398, packed tarball, installed dist identical to the final build, egress blocked, provider hosts redirected to spec-validating fake servers: 0 contract violations, all SigV4 signatures valid), SQLite and PostgreSQL 16:

  • 96 measured states on SQLite (1440/768/390/320 × light/dark × 12 states) and 48 on PostgreSQL (1440/390): document overflow 0, no clipping, nothing outside the viewport. Remaining hits are pre-existing (gradient-button contrast artifact, NumberInput steppers) or the DS radio exception (label is part of the target).
  • de/fr/es/pt at 1440 and 320: no placeholder/id leaks, no English leftovers, no "du".
  • Without a template-provider account nothing new is visible. 0 plugin console messages.
  • Click paths 3–4 interactions (table in the acceptance doc); Escape/focus return checked on the new dialogs.
  • After the rebase onto the updated feat: provider templates for SendGrid and Mailgun #20: fresh SQLite host smoke (HTTP checks, all 11 click-path checks, 48 measured states at 1440/390 light+dark) with the same results.
  • Found on the host and fixed: the test-send locale field was stripped by validate() (renamed to language, regression test added).

Live suite (pending)

Add to ~/.config/magic-mail-live/.env: BREVO_API_KEY, BREVO_FROM, BREVO_TO, optional BREVO_TEMPLATE_ID; SES_REGION, SES_ACCESS_KEY_ID, SES_SECRET_ACCESS_KEY, SES_FROM, optional SES_CONFIGURATION_SET, SES_TEMPLATE_NAME. Brevo runs with X-Sib-Sandbox: drop; SES sends only to the mailbox simulator. Today all 15 tests skip with the missing names. Unverified until then: Brevo's bearer header and error texts, SES ConfigurationOverrides acceptance, a real SNS certificate.

Docs read (2026-11-18): developers.brevo.com (send-transac-email, smtp templates, get-account, create-webhook, secured-webhooks, transactional-webhooks, sandbox mode, api limits, limit headers, ip security) and their OpenAPI files; AWS SES v2 API (SendEmail, GetAccount, ListEmailTemplates, GetEmailTemplate, CommonErrors), SES developer guide (quotas, event publishing, SNS event contents, mailbox simulator), SNS signature verification and HTTP/S subscription docs, IAM "Create a signed AWS API request"; MDN Intl.getCanonicalLocales; installed Strapi Design System 2.2.4 sources.

🤖 Generated with Claude Code

@Schero94
Schero94 force-pushed the feat/providers-brevo-ses branch from adfd98c to 2473c47 Compare November 18, 2026 23:06
@Schero94
Schero94 force-pushed the feat/provider-templates branch from 882a86a to 936a874 Compare November 18, 2026 23:08
…open/click tracking

Re-landed on main after #20 was squash-merged: the changes of #28 (diff from
its #20 base 882a86a) applied onto origin/main, CHANGELOG [Unreleased]
merged with #20's entries, StrictMode admin tests added for the Brevo/SES
credentials steps and connection check, the Brevo template dialog with
language versions and the provider-tracking switch.

- Brevo: send, Check connection, webhook token (reveal/rotate, audited),
  templates with params; Amazon SES v2: own SigV4 (38 official vectors),
  send, templates, Check connection, SNS-verified events.
- Language versions of provider templates (exact -> language -> default).
- Provider open/click events counted for provider-template mails.
- Brevo and Amazon SES are labelled Beta in the wizard until a live run
  against their APIs passes (see CHANGELOG Verification).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Schero94
Schero94 force-pushed the feat/providers-brevo-ses branch from dc4669e to d51f09f Compare November 18, 2026 23:17
@Schero94
Schero94 changed the base branch from feat/provider-templates to main November 18, 2026 23:17
Schero94 and others added 3 commits November 19, 2026 07:49
…open/click tracking

Re-landed on main after #20 was squash-merged: the changes of #28 (diff from
its #20 base 882a86a) applied onto origin/main, CHANGELOG [Unreleased]
merged with #20's entries, StrictMode admin tests added for the Brevo/SES
credentials steps and connection check, the Brevo template dialog with
language versions and the provider-tracking switch.

- Brevo: send, Check connection, webhook token (reveal/rotate, audited),
  templates with params; Amazon SES v2: own SigV4 (38 official vectors),
  send, templates, Check connection, SNS-verified events.
- Language versions of provider templates (exact -> language -> default).
- Provider open/click events counted for provider-template mails.
- Brevo and Amazon SES are labelled Beta in the wizard until a live run
  against their APIs passes (see CHANGELOG Verification).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…he tree is the re-land on 4.8.0

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… (React 19 key warning)

Found by the informational React 19 StrictMode job.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Schero94
Schero94 marked this pull request as ready for review November 19, 2026 12:03
@Schero94
Schero94 merged commit b2c8253 into main Nov 19, 2026
8 checks passed
github-actions Bot pushed a commit that referenced this pull request Nov 19, 2026
# [4.9.0](v4.8.0...v4.9.0) (2026-11-19)

### Features

* Brevo and Amazon SES accounts, template languages and provider open/click tracking ([#28](#28)) ([b2c8253](b2c8253))

### Added

* **Brevo accounts.** Send through the Brevo transactional API (`api-key` header) with sender, cc/bcc, reply-to, attachments, filtered headers and the `magicmail_id` correlation header. **Check connection** reads the Brevo account without sending and names the cause of a failure (invalid key, IP not authorised, account under validation, no credits). Brevo templates sync like SendGrid and Mailgun templates and are sent with `templateId` and your `data` as `params` (a Brevo template writes `{{ params.name }}`, you pass `name`). Delivery webhooks are authenticated with a random webhook token MagicMail creates per account (**Show webhook token**, **Replace token**).
* **Amazon SES accounts.** Send through the SES v2 API in any commercial or GovCloud region, signed with AWS Signature Version 4 (own implementation, tested against the official AWS SigV4 test suite; no AWS SDK). Credentials are an IAM access key or the server's environment variables (`AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `AWS_SESSION_TOKEN`). **Check connection** shows sandbox and sending status. SES templates sync and are sent with `TemplateData`. Bounces, complaints, deliveries, delays, rejects and opens/clicks arrive through an SES configuration set → SNS → HTTPS subscription; every SNS message is checked against the configured topic ARN and the SNS signature, and the subscription is confirmed automatically.
* **Language versions for provider templates.** A provider template can map languages (`de`, `fr`, `pt-BR`, …) to other synced templates of the same provider. `send({ providerTemplate, locale })` picks the exact language, then the base language, then the default; without `locale` the recipient's stored locale is used when the users-permissions user type has a `locale` attribute. Core emails use the user's locale and send it as `meta.locale`; test sends use the admin's interface language or `language`. Unusable versions are skipped.
* **Opens and clicks of provider-rendered mails.** New setting **Count provider opens and clicks** (off by default; shown only with a SendGrid, Mailgun, Brevo or SES account). Provider-template sends then ask the provider to track, and the provider's open and click webhook events (SendGrid, Mailgun, Brevo, SES) are counted in Email Analytics, only for those mails, so nothing is counted twice. Clicked links are stored as origin and path only.
* **admin API:** `POST /magic-mail/accounts/:accountId/check` (`test-send`, read-only), `POST /magic-mail/accounts/:accountId/webhook-token` (`manage`, browser sessions only, audit-logged), `locales` in `PUT /magic-mail/provider-templates/:key/settings`, `language` in `POST /magic-mail/provider-templates/:key/test-send`. Content API: `POST /api/magic-mail/webhooks/brevo/:accountId`, `POST /api/magic-mail/webhooks/ses/:accountId`.

### Security

* Brevo webhooks have no provider signature; MagicMail requires a 256-bit random token per account (constant-time comparison, encrypted at rest, revealed only to browser sessions with `manage`, every reveal logged without the token). SNS messages for SES are verified (topic ARN, certificate host `sns.<region>.amazonaws.com` of the topic's region, no redirects, size-capped certificate fetch, SignatureVersion 1 and 2) before anything is processed. AWS credentials are never read from instance-metadata or ECS endpoints. Provider error bodies are never logged or returned; Brevo and SES connection checks return no personal data.

### Migration

* Brevo, Amazon SES, language versions and provider tracking: nothing to do. The email log gets an optional `providerTracking` flag and the settings an optional `providerTracking` switch (off). SendGrid, Mailgun and SMTP requests are unchanged (golden payload tests). `PUT /provider-templates/:key/settings` now accepts `locales`, and `fallbackTemplateReferenceId` is optional there (at least one of the two is required).

### Verification

* **Brevo and Amazon SES are marked Beta in the account wizard.** Both are verified against their official API descriptions (Brevo OpenAPI files, the Amazon SES v2 Smithy model), by contract tests on every request and response, by the 38 official AWS SigV4 test vectors and by integration tests against fake servers built from those descriptions, plus a browser acceptance run on Strapi 5.62.0 (SQLite and PostgreSQL). **They have not yet been tested against the live Brevo and Amazon SES APIs.** Only a live run (`npm run test:live` with the `BREVO_*` and `SES_*` variables) can confirm:
  1. which header Brevo sends for bearer-token webhook authentication (`Authorization: Bearer <token>` is assumed; the custom header `X-Magic-Mail-Webhook-Token` also works);
  2. the wording of Brevo's error messages that select the specific hints (IP not authorised, sender not verified, unknown template); other errors fall back to the hint for their status code;
  3. that Amazon SES accepts the per-message `ConfigurationOverrides.Tracking` field used for provider open and click tracking;
  4. that SES answers `404 NotFoundException` for an unknown template on `SendEmail`;
  5. the verification of a real SNS signing certificate (the tests use self-signed certificates; trust rests on HTTPS to the fixed `sns.<region>.amazonaws.com` host).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant