Skip to content

feat(providers): SendGrid EU region and safer SendGrid/Mailgun send paths - #23

Merged
Schero94 merged 14 commits into
mainfrom
fix/provider-send-paths
Nov 18, 2026
Merged

Schero94 merged 14 commits into
mainfrom
fix/provider-send-paths

Conversation

@Schero94

Copy link
Copy Markdown
Owner

Waiting for the live run (npm run test:live with ~/.config/magic-mail-live/.env) before merge. This PR changes what is sent to SendGrid and Mailgun, so it stays open until the live suite has passed against both providers. The file does not exist yet; without it every live test is skipped.

What changes

SendGrid

  • EU regional subusers (SG-2, ACC-SG-01): config.region us (default, legacy) or eu → https://api.sendgrid.com / https://api.eu.sendgrid.com (new server/src/utils/sendgrid-region.js). Unknown regions are rejected on create and update (assertSendGridRegion). The wizard gets a region SingleSelect with i18n in 5 locales. The failure log line names the region.
  • Duplicates (SG-1): every address is sent once across to, then cc, then bcc (case-insensitive, first occurrence wins). An empty cc/bcc is left out. Only SendGrid does this: Mailgun documents "Duplicate addresses are automatically ignored", and SMTP/Gmail/Graph output stays byte-identical.
  • Display names (SG-9): kept as MailTo.name. No new lower-casing was added.
  • Reserved headers (SG-3): x-sg-id and x-sg-eid are added to RESERVED_X_HEADERS.
  • Size (SG-7): a JSON body of 30 MB or more is refused before fetch with ValidationError code MAGIC_MAIL_MESSAGE_TOO_LARGE. HTTP 413 gets the same code.
  • Errors (SG-5):
    • At most 4 KB of the error body is read, with a 2 s timeout.
    • Only allowlisted errors[].field paths are kept, as error.providerFields.
    • error.provider is set to sendgrid or mailgun.
    • The message stays "<Provider> API request failed: <status>".
    • The provider's text is never logged, stored or returned.
    • A 403 "verified Sender Identity" sets error.providerReason = 'sender_identity' without storing the text.
    • On 429, X-RateLimit-Reset is used as a lower bound for the next queue attempt, only when it is an integer within 24 h.
  • Correlation (SG-8): custom_args.magicmail_id is the email-log documentId (/^[A-Za-z0-9]{1,64}$/). This matches the magicmail_id parser merged in feat(webhooks): record delivery outcomes, feed suppression and fix bounce analytics #21; a test feeds the sent values back through parseSendGridEvents / parseMailgunEvent.
  • Tracking (MG-SEND-3): tracking_settings.open_tracking / click_tracking { enable: false } is sent only for the parts Magic Mail really applied. applyTracking reports these in data.__trackingApplied, and analytics.addTracking gained an optional applied out-parameter.

Mailgun

  • Size (MG-SEND-1): a message estimated at 25 MB or more (base64-inflated) is refused before fetch.
  • Options limit (MG-SEND-2): o:/h:/v:/t: options over 16 KB (Buffer.byteLength) are refused on every send. Caller headers are capped at 8 KB for all providers: the zod schema in validation.js answers 400, and filterCustomHeaders drops headers past the budget.
  • Tracking: o:tracking-opens=no / o:tracking-clicks=no, only for the applied parts.
  • Metadata (MG-SEND-4): v:magicmail_email_type and v:magicmail_priority (allowlisted values), v:magicmail_id, and o:tag=<type> (ASCII, at most 128 characters).

All providers: attachments are limited to 40 MB raw in total (normalizeAttachments, code MAGIC_MAIL_MESSAGE_TOO_LARGE).

Queue:

  • The worker passes __logDocumentId.
  • __trackingApplied is now part of the encrypted payload; older rows simply lack it, which means no provider tracking flags.
  • retryAfterMs sets a lower bound on the next retry (retryLowerBoundMs in delivery-outcome.js).

Not changed, by decision

  • SendGrid 403 stays transient. Making it permanent would disable failover to another account whose sender is verified. The reason is exposed as providerReason instead.
  • send() still lower-cases addresses for every provider (separate observation, SG-9 note; not touched).

Functions changed or added in server/src/services/email-router.js (for rebasing #20)

  • Changed: providerHttpError (new details parameter; sets provider and the 413 code), normalizeAttachments, filterCustomHeaders, send (sets data.__logDocumentId), applyTracking, sendViaSendGrid (rewritten), sendViaMailgun, module.exports.__test__.
  • Constants: RESERVED_X_HEADERS, plus new SENDGRID_MAX_MESSAGE_BYTES (30 000 000), MAILGUN_MAX_MESSAGE_BYTES, MAILGUN_MAX_OPTIONS_BYTES (16 KiB), MAX_TOTAL_ATTACHMENT_BYTES, MAX_CUSTOM_HEADER_BYTES, PROVIDER_ERROR_BODY_*, MAX_RATE_LIMIT_RESET_MS, MAGICMAIL_ID_PATTERN, MAILGUN_TAG_MAX_LENGTH, SENDGRID_ERROR_FIELD, MAX_PROVIDER_FIELDS.
  • Added (module level): messageTooLargeError, readProviderErrorBody, sendGridErrorDetails, rateLimitResetMs, sendGridRecipients, trackingAppliedOf, magicmailIdOf, mailgunTag, mailgunOptionBytes (same body as feat: provider templates for SendGrid and Mailgun #20), estimateMailgunMessageBytes.
  • Import: resolveSendGridRegion, sendGridApiBaseUrl from ../utils/sendgrid-region.

On rebase, #20 should:

  • make utils/provider-api.js re-export SENDGRID_REGIONS, resolveSendGridRegion and sendGridApiBaseUrl from utils/sendgrid-region.js;
  • keep this branch's constants (its SendGrid cap was 30 MiB, here it is 30 000 000 because the docs say "less than 30MB");
  • drop its template && condition on the Mailgun 16 KB check, which now runs for every send;
  • re-record its golden fixtures, because local-* now gain magicmail_id, the tracking_settings / o:tracking-* fields and the Mailgun v:/o:tag fields.

The wizard hunks, i18n keys and values, assertSendGridRegion, the delivery-webhooks.test.js hunk, the package.json lines and the vendored specs and helpers are byte-identical to #20.

Tests

  • tests/provider-send-golden.test.js: payloads recorded from 4.5.1 before the edits (first commit). SendGrid and Mailgun output is identical except the listed added fields; SMTP is byte-identical.
  • tests/provider-send-contract.test.js: built bodies and fake responses are validated against the pinned sendgrid-mail.json / mailgun.json, with sha256 equal to feat: provider templates for SendGrid and Mailgun #20. It also asserts the plan section 2 invariants.
  • tests/provider-send-paths.test.js: 32 behaviour tests, including a ReDoS time budget and the queue lower bound.
  • tests/live/provider-send.live.test.js: opt-in, with SendGrid sandbox mode and Mailgun o:testmode=yes. The variable names are listed in the file header and in the README. It skips cleanly without the file.

Gates (local, Node 22)

  • lint, format:check, test (574 pass, 3 skipped as before), build, verify, verify:runtime: all clean.
  • npm audit --omit=dev: 0.
  • test:live: 15 skipped (no .env).
  • Browser: isolated Strapi 5.62.0 host (port 1397, SQLite, egress blocked, packed tarball).
    • The wizard region select shows EU for an eu account and lists both options.
    • Measured at 1440 and 390 in light and dark: documentOverflow 0, no clipped text, no small targets, nothing outside the viewport.
    • The only lowContrast hit is the pre-existing gradient Continue button (a measurement artifact).
    • 0 console messages from the changed field. A pre-existing DS warning Missing Description … for {DialogContent} appears when the wizard modal opens, before this step is reached.
    • Over HTTP, a create with region: 'mars' answered 400 and one with region: 'eu' answered 200.

Docs read (2026-11-18): Twilio Mail Send (Limitations, errors), rate-limits, Mailgun send-http, and the pinned OpenAPI specs.

🤖 Generated with Claude Code

Schero94 and others added 5 commits November 18, 2026 07:34
Recorded from main c457477 before the provider send-path fixes, so the
following commits can prove that normal sends keep their recipients,
content, headers and attachments.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ct helper

Byte-identical copies of feat/provider-templates (sha256 checked):
tests/fixtures/openapi/{sendgrid-mail,mailgun}.json,
tests/helpers/openapi-contract.js and tests/helpers/extract-openapi.js,
plus the ajv ^8.20.0 devDependency and the test:live script with the
same lines, so both branches rebase without conflicts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…aths

SendGrid
- SG-2/ACC-SG-01: config.region 'us' | 'eu' (default/legacy 'us') maps to
  api.sendgrid.com / api.eu.sendgrid.com (utils/sendgrid-region.js);
  rejected on account create/update; wizard SingleSelect with i18n in 5
  locales (same keys, values and hunks as feat/provider-templates); the
  failure log line names the region.
- SG-1/SG-9: every address once across to, cc, bcc (case-insensitive,
  first wins, empty cc/bcc dropped) with MailTo.name kept.
- SG-3: x-sg-id and x-sg-eid are reserved headers.
- SG-7: request bodies of 30 MB or more are refused before fetch with
  ValidationError MAGIC_MAIL_MESSAGE_TOO_LARGE; HTTP 413 gets the code.
- SG-5: on failure at most 4 KB of the body is read (2 s timeout); only
  allowlisted errors[].field paths are kept (error.providerFields), the
  verified-sender 403 is flagged as providerReason 'sender_identity'
  without keeping text; error.provider is set; message stays
  "<Provider> API request failed: <status>". 429 X-RateLimit-Reset is a
  lower bound for the queue retry when it is an integer within 24 h.
- SG-8: custom_args.magicmail_id = email-log documentId.
- MG-SEND-3: tracking_settings open/click enable:false only for the parts
  Magic Mail applied.

Mailgun
- MG-SEND-1: estimated messages of 25 MB or more are refused before fetch.
- MG-SEND-2: o:/h:/v:/t: options over 16 KB are refused on every send;
  caller headers are capped at 8 KB for every provider (zod + filter).
- MG-SEND-3: o:tracking-opens/-clicks=no only for applied parts.
- MG-SEND-4/SG-8: v:magicmail_email_type, v:magicmail_priority,
  v:magicmail_id and o:tag=<type>.

All providers: attachments are limited to 40 MB raw in total.

Tests: golden payloads recorded from 4.5.1 stay identical except the
listed additions; contract tests against the pinned specs; behaviour
tests; opt-in live suite tests/live/provider-send.live.test.js (skips
without ~/.config/magic-mail-live/.env).

Docs read (2026-11-18): twilio.com/docs/sendgrid/api-reference/mail-send
(Limitations, errors), .../how-to-use-the-sendgrid-v3-api/rate-limits,
documentation.mailgun.com .../sending-messages/send-http, pinned
tsg_mail_v3.json and mailgun.json (servers, PostMailSend, MailTo,
ErrorResponse, tracking_settings, o:tracking-*, o:tag, v:, 16KB rule).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Keeps the Mailgun domain normalisation from #22 next to the SendGrid region check, moves this branch's changelog entries back under [Unreleased] (the merge had placed them inside the released 4.6.0 section) and adds its README What's new bullets.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Schero94

Copy link
Copy Markdown
Owner Author

Merged main 4.6.1 (#21, #22) into this branch at 4886c3a. CI is green. The changelog entries are back under [Unreleased], and README What's new is ready.

Still waiting for the live run (npm run test:live with ~/.config/magic-mail-live/.env) before merge. All 15 live tests currently skip.

Open decision before merge: the Content API now rejects custom headers over 8 KB in total with a 400. That is a stricter validation, and under the workbench semver rules it counts as breaking. Two options:

  • Keep it, with a BREAKING CHANGE footer, which makes this a major release.
  • Drop the zod rule and keep only the Mailgun 16 KB precheck plus the service-side header budget, which keeps this a minor release.

🤖 Generated with Claude Code

Drops the new zod rule that answered 400 for more than 8 KB of custom headers, so no request that passed before is rejected now. Magic Mail still sends at most 8 KB of caller headers, and a Mailgun message over the 16 KB options limit still fails before the request with MAGIC_MAIL_MESSAGE_TOO_LARGE.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Schero94

Copy link
Copy Markdown
Owner Author

Decision applied in 905c1ff: the Content API rule that answered 400 for more than 8 KB of custom headers is removed. validation.js is now identical to main, so this stays a minor release.

Still in place:

  • Magic Mail sends at most 8 KB of caller headers; the ones past that are left out.
  • A Mailgun message over the 16 KB options limit fails before the request with MAGIC_MAIL_MESSAGE_TOO_LARGE.

Updated: tests, CHANGELOG [Unreleased] and docs/sending.md. Full gate passes, CI is green.

This PR still waits for the live run (npm run test:live with ~/.config/magic-mail-live/.env) before merge.

🤖 Generated with Claude Code

…n's 16 KB limit

Removes the 8 KB caller-header budget that silently dropped headers. Headers pass through exactly as in 4.6.1 (allowlist and 20-header rule unchanged). Only the documented Mailgun limit (send options at most 16 KB, mailgun.json POST /v3/{domain_name}/messages) fails before the request, with MAGIC_MAIL_MESSAGE_TOO_LARGE. SendGrid documents no header size limit (https://www.twilio.com/docs/sendgrid/api-reference/mail-send/mail-send, checked 2026-11-18), so there is no SendGrid precheck; its own 400 carries the rejected field name.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Schero94

Copy link
Copy Markdown
Owner Author

Correction to my earlier comment, applied in 596ef01: the 8 KB budget that silently dropped caller headers is removed. filterCustomHeaders and validation.js are identical to main, so headers are sent exactly as in 4.6.1. Nothing is dropped or shortened for size.

The only header limit left is Mailgun's documented one: all send options together must stay at or under 16 KB (mailgun.json, POST /v3/{domain_name}/messages). Above that, the send fails before the request with MAGIC_MAIL_MESSAGE_TOO_LARGE.

SendGrid documents no header size limit (https://www.twilio.com/docs/sendgrid/api-reference/mail-send/mail-send, checked 2026-11-18), so there is no SendGrid precheck. SendGrid's own 400 carries the rejected field name.

Updated: the tests (headers pass through unchanged for SendGrid and below 16 KB for Mailgun, explicit error above), CHANGELOG [Unreleased] (the "headers past 8 KB" migration line is removed) and docs/sending.md. Full gate passes, CI is green.

This PR still waits for the live run before merge.

🤖 Generated with Claude Code

Schero94 added a commit that referenced this pull request Nov 18, 2026
The local-template and core-mail golden fixtures now include exactly the
fields the SendGrid/Mailgun send-path changes (#23) add on purpose; every
other byte is unchanged (checked by stripping the added keys and comparing
with the previous fixtures):

- SendGrid: custom_args.magicmail_id and tracking_settings with
  open_tracking/click_tracking enable=false for the parts Magic Mail tracks
- Mailgun: o:tracking-opens=no / o:tracking-clicks=no (tracked parts only),
  v:magicmail_email_type, v:magicmail_priority, v:magicmail_id, o:tag
- SMTP fixtures: unchanged

The fake delivery log now returns alphanumeric documentIds like real Strapi
ones (golddoc1 instead of log-1); #23 sends only ids matching
/^[A-Za-z0-9]{1,64}$/, so the old id silently suppressed magicmail_id.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Schero94 added a commit that referenced this pull request Nov 18, 2026
…d 16 KB check

SendGrid template sends get custom_args.magicmail_id, Mailgun template sends
get v:magicmail_id, v:magicmail_email_type, v:magicmail_priority and o:tag,
and neither gets provider tracking switches (the provider renders the body).
The Mailgun 16 KB send-options check now runs once on every send, so template
data that fits alone but not with the metadata is refused before any request
with MAGIC_MAIL_PROVIDER_TEMPLATE_TOO_LARGE; exactly 16 KB is accepted.

The fake delivery log returns alphanumeric documentIds like Strapi does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Schero94 added a commit that referenced this pull request Nov 18, 2026
…mode

The sandboxed preview iframe used the theme's neutral0 background, so in
dark mode provider templates without their own text colour rendered black
text on a dark canvas. The preview now uses the light DS canvas
(LIGHT_FALLBACK_COLORS.neutral0, color-scheme: light) in both themes, like a
mail client. Found in the browser smoke after stacking on #23.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Schero94 added a commit that referenced this pull request Nov 18, 2026
…uites still pending)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Schero94 and others added 2 commits November 18, 2026 16:04
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
send() split to/cc/bcc strings on every comma, also inside quoted
display names, and lower-cased the pieces, so "Ops, Live" <cc@x>
reached every provider as "ops,  Live" <cc@x> (also on main 4.6.1).
Recipients are now parsed with nodemailer's RFC 5322 address parser,
the one the transports already use; only the address part is
lower-cased and the name is kept, quoted only when it needs quotes.
Bare address lists normalise exactly as before (golden fixtures
unchanged). Found by the live SendGrid run (SG-9).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Schero94 added a commit that referenced this pull request Nov 18, 2026
The local-template and core-mail golden fixtures now include exactly the
fields the SendGrid/Mailgun send-path changes (#23) add on purpose; every
other byte is unchanged (checked by stripping the added keys and comparing
with the previous fixtures):

- SendGrid: custom_args.magicmail_id and tracking_settings with
  open_tracking/click_tracking enable=false for the parts Magic Mail tracks
- Mailgun: o:tracking-opens=no / o:tracking-clicks=no (tracked parts only),
  v:magicmail_email_type, v:magicmail_priority, v:magicmail_id, o:tag
- SMTP fixtures: unchanged

The fake delivery log now returns alphanumeric documentIds like real Strapi
ones (golddoc1 instead of log-1); #23 sends only ids matching
/^[A-Za-z0-9]{1,64}$/, so the old id silently suppressed magicmail_id.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Schero94 added a commit that referenced this pull request Nov 18, 2026
…d 16 KB check

SendGrid template sends get custom_args.magicmail_id, Mailgun template sends
get v:magicmail_id, v:magicmail_email_type, v:magicmail_priority and o:tag,
and neither gets provider tracking switches (the provider renders the body).
The Mailgun 16 KB send-options check now runs once on every send, so template
data that fits alone but not with the metadata is refused before any request
with MAGIC_MAIL_PROVIDER_TEMPLATE_TOO_LARGE; exactly 16 KB is accepted.

The fake delivery log returns alphanumeric documentIds like Strapi does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Schero94 added a commit that referenced this pull request Nov 18, 2026
…mode

The sandboxed preview iframe used the theme's neutral0 background, so in
dark mode provider templates without their own text colour rendered black
text on a dark canvas. The preview now uses the light DS canvas
(LIGHT_FALLBACK_COLORS.neutral0, color-scheme: light) in both themes, like a
mail client. Found in the browser smoke after stacking on #23.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Schero94 added a commit that referenced this pull request Nov 18, 2026
…uites still pending)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n test

SendGrid answers POST /v3/mail/send with 401 both for a wrong key and
for a valid key without the mail.send scope (observed live), so the
account test said "SendGrid rejected the API key". After a SendGrid
401/403 the test now makes one read-only GET /v3/scopes (documented to
list the scopes of the calling key): a valid key without mail.send gets
the new hint SENDGRID_MISSING_MAIL_SEND, a rejected key keeps
SENDGRID_UNAUTHORIZED, a 403 with mail.send keeps SENDGRID_FORBIDDEN,
and any failure of the check keeps the status mapping. The response is
bounded, only the scopes array is read, nothing from it reaches the
client or the log. Translated in five locales.

docs/live-webhook-checks.md: the SendGrid test event is signed, and
"Test Your Integration" adds SendGrid's sample address to the
suppression list; how to remove it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Schero94 added a commit that referenced this pull request Nov 18, 2026
The local-template and core-mail golden fixtures now include exactly the
fields the SendGrid/Mailgun send-path changes (#23) add on purpose; every
other byte is unchanged (checked by stripping the added keys and comparing
with the previous fixtures):

- SendGrid: custom_args.magicmail_id and tracking_settings with
  open_tracking/click_tracking enable=false for the parts Magic Mail tracks
- Mailgun: o:tracking-opens=no / o:tracking-clicks=no (tracked parts only),
  v:magicmail_email_type, v:magicmail_priority, v:magicmail_id, o:tag
- SMTP fixtures: unchanged

The fake delivery log now returns alphanumeric documentIds like real Strapi
ones (golddoc1 instead of log-1); #23 sends only ids matching
/^[A-Za-z0-9]{1,64}$/, so the old id silently suppressed magicmail_id.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Schero94 added a commit that referenced this pull request Nov 18, 2026
…d 16 KB check

SendGrid template sends get custom_args.magicmail_id, Mailgun template sends
get v:magicmail_id, v:magicmail_email_type, v:magicmail_priority and o:tag,
and neither gets provider tracking switches (the provider renders the body).
The Mailgun 16 KB send-options check now runs once on every send, so template
data that fits alone but not with the metadata is refused before any request
with MAGIC_MAIL_PROVIDER_TEMPLATE_TOO_LARGE; exactly 16 KB is accepted.

The fake delivery log returns alphanumeric documentIds like Strapi does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Schero94 added a commit that referenced this pull request Nov 18, 2026
…mode

The sandboxed preview iframe used the theme's neutral0 background, so in
dark mode provider templates without their own text colour rendered black
text on a dark canvas. The preview now uses the light DS canvas
(LIGHT_FALLBACK_COLORS.neutral0, color-scheme: light) in both themes, like a
mail client. Found in the browser smoke after stacking on #23.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Schero94 added a commit that referenced this pull request Nov 18, 2026
…uites still pending)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The display-name fix shipped in 4.6.2 (#25); this branch's copy of it
drops out of the diff. The test keeps this branch's stricter SendGrid
check (SendGrid now receives the names).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Schero94 added a commit that referenced this pull request Nov 18, 2026
The local-template and core-mail golden fixtures now include exactly the
fields the SendGrid/Mailgun send-path changes (#23) add on purpose; every
other byte is unchanged (checked by stripping the added keys and comparing
with the previous fixtures):

- SendGrid: custom_args.magicmail_id and tracking_settings with
  open_tracking/click_tracking enable=false for the parts Magic Mail tracks
- Mailgun: o:tracking-opens=no / o:tracking-clicks=no (tracked parts only),
  v:magicmail_email_type, v:magicmail_priority, v:magicmail_id, o:tag
- SMTP fixtures: unchanged

The fake delivery log now returns alphanumeric documentIds like real Strapi
ones (golddoc1 instead of log-1); #23 sends only ids matching
/^[A-Za-z0-9]{1,64}$/, so the old id silently suppressed magicmail_id.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Schero94 added a commit that referenced this pull request Nov 18, 2026
…d 16 KB check

SendGrid template sends get custom_args.magicmail_id, Mailgun template sends
get v:magicmail_id, v:magicmail_email_type, v:magicmail_priority and o:tag,
and neither gets provider tracking switches (the provider renders the body).
The Mailgun 16 KB send-options check now runs once on every send, so template
data that fits alone but not with the metadata is refused before any request
with MAGIC_MAIL_PROVIDER_TEMPLATE_TOO_LARGE; exactly 16 KB is accepted.

The fake delivery log returns alphanumeric documentIds like Strapi does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Schero94 added a commit that referenced this pull request Nov 18, 2026
…mode

The sandboxed preview iframe used the theme's neutral0 background, so in
dark mode provider templates without their own text colour rendered black
text on a dark canvas. The preview now uses the light DS canvas
(LIGHT_FALLBACK_COLORS.neutral0, color-scheme: light) in both themes, like a
mail client. Found in the browser smoke after stacking on #23.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Schero94 added a commit that referenced this pull request Nov 18, 2026
…uites still pending)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Schero94 and others added 3 commits November 18, 2026 23:38
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	package-lock.json
#	package.json
@Schero94
Schero94 merged commit f949c98 into main Nov 18, 2026
8 checks passed
github-actions Bot pushed a commit that referenced this pull request Nov 18, 2026
# [4.7.0](v4.6.3...v4.7.0) (2026-11-18)

### Features

* **providers:** SendGrid EU region and safer SendGrid/Mailgun send paths ([#23](#23)) ([f949c98](f949c98))

### Added

* **SendGrid EU regional subusers.** A SendGrid account now has a region: **Global** (default, `api.sendgrid.com`) or **EU** (`api.eu.sendgrid.com`). If your SendGrid key belongs to an EU regional subuser, open the account, choose region **EU** and save. Existing accounts keep the global host; nothing changes for them. An unknown region is rejected when the account is saved.
* **Mailgun sends carry Magic Mail metadata.** Each Mailgun mail gets the variables `magicmail_email_type`, `magicmail_priority` and `magicmail_id` (the email log id) and one tag with the email type (`transactional`, `marketing` or `notification`), so you can filter Mailgun's logs and webhooks by type. SendGrid mails carry `magicmail_id` as a custom argument. Mailgun shows variables to recipients in the `X-Mailgun-Variables` header; they contain no personal data.

### Fixed

* **Duplicate recipients no longer make SendGrid reject the whole email.** SendGrid refuses a mail when an address appears twice in to, cc or bcc. Magic Mail now sends every address once (the first occurrence wins, compared without case) and drops a cc or bcc list that only repeated other addresses. Other providers are unchanged (Mailgun ignores duplicates itself).
* **SendGrid keeps recipient names.** `Ada Lovelace <ada@example.com>` arrives as "Ada Lovelace" instead of the bare address.
* **The SendGrid connection test names a missing Mail Send permission.** SendGrid answers a key without the Mail Send permission with the same 401 as a wrong key, so the test used to say "SendGrid rejected the API key". After a 401 or 403 the test now makes one read-only call (`GET /v3/scopes`): a valid key without Mail Send gets its own hint (`SENDGRID_MISSING_MAIL_SEND`), a wrong key keeps the old one. Nothing from SendGrid's answer is shown.
* **Oversized emails are rejected before upload with a clear message.** SendGrid accepts less than 30 MB and Mailgun 25 MB per message. Magic Mail now checks the size before calling the provider and answers with a validation error (`MAGIC_MAIL_MESSAGE_TOO_LARGE`) instead of uploading the whole mail and getting a vague rejection. All attachments of one email together may be at most 40 MB raw with every provider (each file stays limited to 25 MB). A provider's own "too large" answer (HTTP 413) gets the same code.
* **Magic Mail turns off Mailgun's and SendGrid's own open/click tracking when it tracks itself, so links are no longer wrapped twice** and opens are not counted twice. Only the part Magic Mail really applied is switched off; when Magic Mail does not track (tracking off, no public URL), the provider's tracking settings apply as before.
* **Clear error when headers are too large for Mailgun.** Mailgun allows 16 KB for all headers and options of one message. A Mailgun message above that is now refused before sending with `MAGIC_MAIL_MESSAGE_TOO_LARGE` instead of a bare Mailgun 400. Custom headers are still sent exactly as before; nothing is dropped or shortened.
* **SendGrid's reserved headers are filtered.** A caller header `X-SG-ID` or `X-SG-EID` used to make SendGrid reject the mail; Magic Mail now drops them like its own reserved headers.
* **Clearer provider failures.** Failed SendGrid and Mailgun calls now carry the provider and, for SendGrid, the names of the rejected fields (for example `personalizations.0.cc`), never the provider's message text (it can contain addresses). The error message stays `SendGrid API request failed: <status>`. The server log names the region. When SendGrid answers 429 with a reset time, a queued retry waits at least until then.

### Verification

* SendGrid: every change above was tested live against the real SendGrid API in sandbox mode on 2026-11-18 (sending, account check, webhooks). The EU host could not be tested live (no EU subuser).
* Mailgun: the changes are verified against Mailgun's official OpenAPI specification and with tests, but not yet against the live Mailgun API. Please report anything unexpected.

### Migration

* If you use a SendGrid EU regional subuser, set that account's region to **EU**.
* If you listen to SendGrid or Mailgun webhooks yourself, you will see the new `magicmail_*` custom arguments / variables and the Mailgun tag.
Schero94 added a commit that referenced this pull request Nov 18, 2026
Re-applies #20's own changes (0f3b79f..882a86a) on top of 4.7.0, which
already contains #23. Conflicts resolved in favour of main: the 4.6.3
dialog labelling, the 4.7.0 send paths with the Mail Send hint and the
Strapi 5.63 dev dependencies. The CHANGELOG [Unreleased] section holds
only the provider-template entries plus a Verification section.

Adds the provider-template screens to the StrictMode admin tests: the
templates page loads the overview once, the preview and core-email
design dialogs open and close cleanly, and a stale list starts exactly
one background sync under StrictMode.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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