Skip to content

feat: admin password reset, startup check and events for provider-template core emails - #30

Merged
Schero94 merged 1 commit into
mainfrom
feat/rfc27752-core-mails
Nov 19, 2026
Merged

Schero94 merged 1 commit into
mainfrom
feat/rfc27752-core-mails

Conversation

@Schero94

Copy link
Copy Markdown
Owner

Summary

This PR closes the gaps a strict review found between Magic Mail and Strapi RFC #27752 ("Provider-managed email templates"). It covers SendGrid and Mailgun. Brevo and SES behaviour is unchanged, apart from shared code that is tested.

Must

  1. Admin forgot password via provider template. The new core type is admin-forgot-password. The sendTemplatedEmail shim recognises the call that @strapi/admin 5.63 makes in services/auth.js forgotPassword, which passes { url, user } with admin.forgotPassword.emailTemplate. A call counts as that mail when the data holds exactly url and user, and either the template is the configured object or the link is <admin.absoluteUrl>/auth/reset-password?code=. Payload v1 is { user:{id,email,firstname,lastname,username}, url, token, adminUrl, serverUrl, meta:{templateKey,payloadVersion:1,coreEmailType,locale?,strapiVersion?} }:

    • id and locale (preferedLanguage) come from one best-effort admin::user lookup. It runs only when a design is set.
    • Strict by default. The opt-in fallback "send the Strapi admin email instead" lets Strapi render its own template.
    • The Core emails UI gets a third row, and all five locales are translated. The row is shown only when the design column is, and it has no local editor.
    • Security: only super admins can change this design. setCoreDesign returns 403 to anyone else, and editable hides the button.
  2. Boot-time validation. About 20 s after start (a timer, non-blocking), checkCoreDesigns({ syncIfStale: true }) runs:

    • It syncs a template list older than 10 min (read-only at the provider).
    • It warns with type, key and code only (…_UNKNOWN, …_UNAVAILABLE and the new …_NO_SUBJECT for Mailgun templates without a Subject header, see below), stores coreCheck, and exposes problem, lastSyncedAt, checkedAt and editable per design.
    • CoreDesignAlert and the Core emails notice name each mail with its reason and the time of the last check.
  3. Integration tests against the fake providers (tests/core-mails-integration.test.js):

    • email confirmation end to end through SendGrid and through Mailgun;
    • the Mailgun core path for reset password and admin forgot password;
    • SendGrid admin mail with strict error, opt-in fallback and events;
    • the url warning, subject injection, the startup check and NO_SUBJECT.

    Units are in tests/core-mails-units.test.js and the admin UI checks in tests/admin/strict-mode.test.jsx.

Should

  1. SendGrid subject: a passed subject is copied into dynamic_template_data.subject when the data has no subject (CR/LF stripped). The Twilio Mail Send reference says dynamic_template_data fills the template's subject; the template must use {{subject}}. Documented in docs/sending.md.
  2. meta.strapiVersion (additive, from info.strapi). When url cannot be built, a one-time warning per core type names the setting to fix.
  3. Events magic-mail.provider-template.failed and .fallback with { key, code, coreEmailType, fallback? }. They follow the queue emit pattern (best effort, listener errors logged). They come from prepareProviderTemplate, handleProviderTemplateFailure and the core designer fallback.
  4. Docs: what a provider template replaces (U&P/admin subject and body; the shipper email is ignored and the name is used only when it matches the account address), Reply-To (Strapi's value is kept, otherwise the account's), plus a hint in the Core emails tab.
  5. Test sends merge the sample data of every core type in usedByCoreMails.

Additional finding (live)

The Mailgun live template magic-mail-live has no Subject header. Core emails do not pass the Strapi subject on, so such a template would always fail with MAGIC_MAIL_PROVIDER_TEMPLATE_NO_SUBJECT. Core designs on such templates are now reported as unusable: in the startup log, on the dashboard, with a badge, and with a warning in the design dialog. The send path itself is unchanged.

Compatibility

  • Golden payload tests are unchanged and green. Payload v1 only gains keys.
  • GET /designer/core-designs returns a third entry and new fields.
  • A SendGrid template send with subject now carries subject in dynamic_template_data; templates without {{subject}} are unaffected.
  • Rebased onto fix(mailgun): refuse deleted Mailgun templates before sending; no suppression for ESP blocks #29 (Mailgun template preflight). Conflicts were only in CHANGELOG.md and docs/sending.md and were resolved by keeping both sides.

Verification

  • npm test: 945 pass, 0 fail (3 skipped as before). npm run test:admin: 22 pass. npm run lint and npm run format:check are clean. npm run build, verify, verify:runtime and npm pack --dry-run all pass.
  • Live (real APIs), LIVE_PROVIDERS=sendgrid,mailgun npm run test:live, after the rebase onto fix(mailgun): refuse deleted Mailgun templates before sending; no suppression for ESP blocks #29: 47 pass, 0 fail, 20 skipped (Brevo/SES not selected, no EU accounts). The new tests/live/core-mails.live.test.js covers:
    • SendGrid (sandbox mode): email-confirmation, reset-password and admin-forgot-password through the real dynamic template were accepted. Subject injection: a synthetic SendGrid template with {{subject}} was created by API, its subject variable was detected after sync, a send was accepted with dynamic_template_data.subject, and the template was deleted afterwards (DELETE 204, then GET 404).
    • Mailgun (o:testmode=yes): all three core emails through a synthetic domain template with a Subject header (created by API, deleted afterwards: DELETE 200, then GET 404) were accepted. With fix(mailgun): refuse deleted Mailgun templates before sending; no suppression for ESP blocks #29 the preflight template check runs live too.
    • Startup check: the real magic-mail-live template (no Subject header) was flagged as NO_SUBJECT.
    • Not proven live: that SendGrid and Mailgun actually render the subject or variables in a delivered mail. Sandbox and test mode only validate and accept. No real delivery was made (0 of the allowed 2). Account state was restored: both synthetic templates were deleted, nothing else was changed.
  • Browser acceptance on an isolated Strapi 5.63.0 host built from the packed tarball (loopback, SQLite, random secrets, egress blocked), with UI states mocked via page.route and synthetic data:
    • Core emails tab, admin design dialog and dashboard alert at 1440, 1024, 768, 390 and 320 px, light and dark: document overflow 0 and no clipped text everywhere. Escape closes the dialog and focus returns to a button.
    • Console noise was only core (useRBAC, React Router future flag), blocked egress, and a 404 for an unmocked synthetic template detail.
    • measure.js flags pre-existing items not touched here: gradient header text, where the contrast heuristic cannot read gradients, and the 20 px DS Checkbox.

Docs read

@strapi/admin 5.63.0 services/auth.js and @strapi/email 5.63.0 services/email.js (installed source); @strapi/core info.strapi; SendGrid dynamic templates and Mail Send reference; Mailgun templates API (create with headers JSON, DELETE template).

🤖 Generated with Claude Code

…plate core emails

Close the gaps of a review against Strapi RFC #27752 (provider-managed email
templates) for SendGrid and Mailgun:

- admin forgot password is the third core email (admin-forgot-password):
  the @strapi/admin sendTemplatedEmail call is recognised and sent through the
  chosen provider template with payload v1 { user, url, token, adminUrl,
  serverUrl, meta }; strict by default, opt-in Strapi fallback; super admins
  only
- startup check (non-blocking, after start) of every core-email template,
  syncs a stale list, logs key and code, shown on the dashboard alert;
  Mailgun templates without Subject header are flagged (NO_SUBJECT)
- events magic-mail.provider-template.failed / .fallback (key, code only)
- meta.strapiVersion (additive) and a one-time warning when url is empty
- SendGrid: a passed subject is copied into dynamic_template_data.subject
- test sends use sample data of every core email using the template
- docs: what a provider template replaces, Reply-To, Core emails hint

Docs read: @strapi/admin 5.63.0 services/auth.js forgotPassword and
@strapi/email 5.63.0 services/email.js (installed source); SendGrid
dynamic templates and Mail Send reference (dynamic_template_data fills
subject); Mailgun templates API (headers JSON, DELETE template).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Schero94
Schero94 merged commit cf3ef8a into main Nov 19, 2026
8 checks passed
@Schero94
Schero94 deleted the feat/rfc27752-core-mails branch November 19, 2026 22:08
github-actions Bot pushed a commit that referenced this pull request Nov 19, 2026
# [4.10.0](v4.9.1...v4.10.0) (2026-11-19)

### Features

* admin password reset, startup check and events for provider-template core emails ([#30](#30)) ([cf3ef8a](cf3ef8a))
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