Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
## [Unreleased]

### Added

* **Admin password reset through a provider template.** The admin panel's "Forgot password?" mail is the third core email (`admin-forgot-password`). Magic Mail recognises the `sendTemplatedEmail` call of `@strapi/admin` 5.x and, when a SendGrid or Mailgun template is chosen under **Email Templates → Core emails → Design** (super admins only), sends it with payload v1 `{ user, url, token, adminUrl, serverUrl, meta }`. Strict by default; **send the Strapi admin email instead** is the opt-in fallback. Without a choice nothing changes.
* **Startup check of core-email templates.** About 20 seconds after start (non-blocking) every core email that uses a provider template is checked; a stale template list is synced first. Unsynced or unusable templates, and Mailgun templates without a Subject header (`MAGIC_MAIL_PROVIDER_TEMPLATE_NO_SUBJECT`; core emails do not pass the Strapi subject on), are logged with type, key and code (never values), and the dashboard and Core emails notices name each affected mail with its reason and the time of the check.
* **Events** `magic-mail.provider-template.failed` and `magic-mail.provider-template.fallback` on `strapi.eventHub` with `{ key, code, coreEmailType, fallback? }` (no personal data).
* **`meta.strapiVersion`** in the core-email payload v1 (additive), and a one-time warning per core email when `url` can not be built because the base URL is empty or relative.
* **SendGrid subject for dynamic templates.** A `subject` passed with a SendGrid provider template is copied into `dynamic_template_data.subject` when the data has none, so a template whose subject line is `{{subject}}` renders it (SendGrid ignores the top-level subject for dynamic templates).
* **Test sends** of a provider template used by several core emails include sample values for every one of them.
* **Docs:** what a provider template replaces for core emails (subject, body, shipper email) and how Reply-To is kept; a short hint in the Core emails tab.

### Fixed

* **Mailgun: a template deleted at Mailgun is no longer logged as sent.** Mailgun accepts a send that names a template it does not have (200 "Queued") and drops the message afterwards (event `failed`, delivery-status 621 "Template not found", retried every 10 minutes). Before a template send MagicMail now checks the template at Mailgun (`GET /v3/{domain}/templates/{name}?active=yes`, account-level templates `GET /v4/templates/{name}?active=yes`). A deleted template, or one without an active version, fails with `MAGIC_MAIL_PROVIDER_TEMPLATE_UNAVAILABLE` before any message is sent: another account that still has the template sends instead, else the configured Magic Mail fallback template, else the error is returned and the delivery log row is `failed`. A successful check is cached for 60 seconds per account and template (one extra request per template and minute for bulk sends, parallel sends share one check). If the check itself fails (network, timeout, 401/403, 429, 5xx), the send goes ahead and a warning is logged.
Expand All @@ -8,6 +18,8 @@
### Migration

* Nothing to do. Mailgun template sends make one extra read request per template and minute; the API key needs read access to templates, which provider-template sync already requires. Addresses suppressed earlier because of a Mailgun `espblock` can be removed under **Plugin Settings → Bounces and recipient checks → Suppressed recipients** (source `mailgun`, reason code `MAILGUN_ESPBLOCK_*`).
* Nothing to do. Core-email payload v1 only gains keys (`meta.strapiVersion`); existing keys and the golden SendGrid/Mailgun payloads are unchanged. `GET /designer/core-designs` returns a third entry `admin-forgot-password` and new fields (`problem`, `lastSyncedAt`, `checkedAt`, `editable`). SendGrid template sends with a `subject` and no `subject` in `data` now carry `subject` in `dynamic_template_data`; templates that do not use `{{subject}}` render as before.


# [4.9.0](https://github.com/Schero94/Magic-Mail/compare/v4.8.0...v4.9.0) (2026-11-19)

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ MagicMail sends email only. It is MIT licensed, with no license key, tiers or us
- **Outbox with retries.** Opt-in per send or for every failed send: 3 retries by default (after 1, 5 and 15 minutes, configurable from 1 to 10), idempotency keys, and an Outbox tab where you retry, discard or mark uncertain mails as sent.
- **Delivery webhooks.** Verified SendGrid, Mailgun, Brevo and Amazon SES (SNS) webhooks record bounces, blocks, complaints, deferrals, deliveries and unsubscribes on the delivery log, feed the suppression list and emit events other plugins can listen to.
- **Templates.** A visual editor (Unlayer) or plain HTML and text, Mustache variables, versions with restore, import and export, plus the Users & Permissions reset and confirmation mails.
- **Provider templates.** Keep designing in SendGrid, Mailgun, Brevo or Amazon SES: their templates appear read-only in MagicMail, with preview, test send, language versions and the same template data your code already passes. Routing, failover and logs stay in MagicMail, and the password-reset and confirmation mails can use them too.
- **Provider templates.** Keep designing in SendGrid, Mailgun, Brevo or Amazon SES: their templates appear read-only in MagicMail, with preview, test send, language versions and the same template data your code already passes. Routing, failover and logs stay in MagicMail, and the password-reset, confirmation and admin password-reset mails can use them too ([core emails](https://github.com/Schero94/Magic-Mail/blob/main/docs/sending.md#provider-templates-sendgrid-mailgun-brevo-amazon-ses)).
- **Analytics.** A delivery log with server-side search, open and click tracking with truncated IPs and configurable retention.
- **Several instances.** Railway replicas or pm2 workers on one database work without sticky sessions or Redis.
- **Admin in five languages.** English, German, French, Spanish and Portuguese, in light and dark mode.
Expand Down
91 changes: 73 additions & 18 deletions admin/src/pages/EmailDesigner/TemplateList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ import { useProviderTemplates } from './providerTemplates/useProviderTemplates';
import { ProviderTemplatesSection } from './providerTemplates/ProviderTemplatesSection';
import { ProviderTemplateDialog } from './providerTemplates/ProviderTemplateDialog';
import { CoreDesignDialog } from './providerTemplates/CoreDesignDialog';
import { CORE_DESIGN_PROBLEMS } from './providerTemplates/CoreDesignAlert';
import { Notice } from './providerTemplates/Notice';
import { providerName, statusInfo } from './providerTemplates/providerTemplateUtils';
import {
Expand Down Expand Up @@ -173,6 +174,16 @@ const TemplateList = () => {
'Sent to confirm a user email address'
),
},
{
type: 'admin-forgot-password',
name: t('templates.core.adminForgotPassword.name', 'Admin password reset'),
description: t(
'templates.core.adminForgotPassword.description',
'Sent when an admin panel user requests a password reset. The local version comes from the Strapi admin configuration.'
),
// Rendered by @strapi/admin from config; Magic Mail only offers the design choice.
designOnly: true,
},
];

// Without read permission nothing is requested, so nothing is loading.
Expand Down Expand Up @@ -781,6 +792,10 @@ const TemplateList = () => {
};

const showDesignColumn = providerEnabled && coreDesigns !== null;
// The admin password reset has no Magic Mail editor: listed only with the design column.
const visibleCoreEmails = coreEmailTypes.filter(
(coreEmail) => !coreEmail.designOnly || showDesignColumn
);
const unusableCoreDesigns = showDesignColumn
? coreEmailTypes.filter((coreEmail) => coreDesigns[coreEmail.type]?.usable === false)
: [];
Expand All @@ -795,7 +810,11 @@ const TemplateList = () => {
</Typography>
);
}
const status = statusInfo(design.status);
// A usable template can still be unusable for core emails (Mailgun without Subject header).
const status =
design.problem === 'MAGIC_MAIL_PROVIDER_TEMPLATE_NO_SUBJECT'
? { tone: 'danger', id: 'templates.coreDesign.badge.noSubject', label: 'No Subject header' }
: statusInfo(design.status);
return (
<Flex direction="column" alignItems="flex-start" gap={1}>
<Typography variant="omega" textColor="neutral800">
Expand Down Expand Up @@ -887,6 +906,14 @@ const TemplateList = () => {
'Design the default Strapi system emails (password reset and email confirmation).'
)}
</Typography>
{showDesignColumn ? (
<Typography variant="pi" textColor="neutral600" tag="p">
{t(
'templates.core.providerHint',
'With a provider template, the subject and body from Users & Permissions or the admin configuration are not used; the provider template renders them. The sender address is always the verified address of the Magic Mail account. A Reply-To set in Strapi is kept.'
)}
</Typography>
) : null}
</Flex>

{unusableCoreDesigns.length > 0 ? (
Expand All @@ -902,14 +929,30 @@ const TemplateList = () => {
{t(
'templates.coreDesign.staleBody',
'{names}: these emails fail until the template is available again and synced, or until you switch back to the Magic Mail designer.',
{ names: unusableCoreDesigns.map((coreEmail) => coreEmail.name).join(', ') }
{
names: unusableCoreDesigns
.map((coreEmail) => {
const problem =
CORE_DESIGN_PROBLEMS[coreDesigns?.[coreEmail.type]?.problem];
return problem
? t('templates.coreDesign.problemItem', '{name} ({reason})', {
name: coreEmail.name,
reason: t(problem.id, problem.label),
})
: coreEmail.name;
})
.join(', '),
}
)}
</Notice>
</Box>
) : null}

<DataTable aria-label={t('templates.core.heading', 'Core email templates')}>
<StyledTable colCount={showDesignColumn ? 3 : 2} rowCount={coreEmailTypes.length + 1}>
<StyledTable
colCount={showDesignColumn ? 3 : 2}
rowCount={visibleCoreEmails.length + 1}
>
<Thead>
<Tr>
<Th>{t('templates.core.table.type', 'Email type')}</Th>
Expand All @@ -922,7 +965,7 @@ const TemplateList = () => {
</Tr>
</Thead>
<Tbody>
{coreEmailTypes.map((coreEmail) => (
{visibleCoreEmails.map((coreEmail) => (
<Tr key={coreEmail.type}>
<Td
className="cell-wrap"
Expand All @@ -947,7 +990,9 @@ const TemplateList = () => {
) : null}
<Td data-label="">
<Flex gap={1} justifyContent="flex-end">
{showDesignColumn && canManage ? (
{showDesignColumn &&
canManage &&
coreDesigns?.[coreEmail.type]?.editable !== false ? (
<IconButton
label={t('templates.coreDesign.choose', 'Choose design of {name}', {
name: coreEmail.name,
Expand All @@ -958,19 +1003,29 @@ const TemplateList = () => {
<Palette aria-hidden="true" />
</IconButton>
) : null}
<IconButton
label={
!canManage
? t('templates.core.view', 'View {name}', { name: coreEmail.name })
: t('templates.core.edit', 'Edit {name}', { name: coreEmail.name })
}
variant="ghost"
onClick={() =>
navigate(`/plugins/magic-mail/designer/core/${coreEmail.type}`)
}
>
{canManage ? <Pencil aria-hidden="true" /> : <Eye aria-hidden="true" />}
</IconButton>
{coreEmail.designOnly ? null : (
<IconButton
label={
!canManage
? t('templates.core.view', 'View {name}', {
name: coreEmail.name,
})
: t('templates.core.edit', 'Edit {name}', {
name: coreEmail.name,
})
}
variant="ghost"
onClick={() =>
navigate(`/plugins/magic-mail/designer/core/${coreEmail.type}`)
}
>
{canManage ? (
<Pencil aria-hidden="true" />
) : (
<Eye aria-hidden="true" />
)}
</IconButton>
)}
</Flex>
</Td>
</Tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useNavigate } from 'react-router-dom';
import { Box } from '@strapi/design-system';
import { TertiaryButton } from '../../../components/StyledButtons';
import { useMagicMailIntl } from '../../../hooks/useMagicMailIntl';
import { useFormatters } from '../../../hooks/useFormatters';
import { Notice } from './Notice';

const CORE_NAMES = {
Expand All @@ -12,18 +13,41 @@ const CORE_NAMES = {
id: 'templates.core.emailConfirmation.name',
label: 'Email address confirmation',
},
'admin-forgot-password': {
id: 'templates.core.adminForgotPassword.name',
label: 'Admin password reset',
},
};

/** Reason text per problem code of a core email design. */
export const CORE_DESIGN_PROBLEMS = {
MAGIC_MAIL_PROVIDER_TEMPLATE_UNKNOWN: {
id: 'templates.coreDesign.problem.unknown',
label: 'not synced',
},
MAGIC_MAIL_PROVIDER_TEMPLATE_UNAVAILABLE: {
id: 'templates.coreDesign.problem.unavailable',
label: 'deleted or unpublished at the provider',
},
MAGIC_MAIL_PROVIDER_TEMPLATE_NO_SUBJECT: {
id: 'templates.coreDesign.problem.noSubject',
label: 'the Mailgun template has no Subject header',
},
};

/**
* Dashboard notice: a core email uses a provider template that is deleted or
* has no active version, so those emails fail. Renders nothing otherwise, and
* nothing without a SendGrid or Mailgun account (`enabled`).
* Dashboard notice: a core email uses a provider template that is not synced,
* deleted or has no active version, so those emails fail. Names each core
* email with the reason (the same check the server runs after start) and the
* time of the last check. Renders nothing otherwise, and nothing without a
* provider-template account (`enabled`).
*
* @param {{enabled: boolean}} props
* @returns {import('react').ReactElement|null}
*/
export const CoreDesignAlert = ({ enabled }) => {
const { t } = useMagicMailIntl();
const { formatDateTime } = useFormatters();
const { get } = useFetchClient();
const navigate = useNavigate();
const [designs, setDesigns] = useState(null);
Expand All @@ -47,6 +71,22 @@ export const CoreDesignAlert = ({ enabled }) => {
const broken = Object.entries(designs ?? {}).filter(([, design]) => design?.usable === false);
if (!enabled || broken.length === 0) return null;

const describe = ([type, design]) => {
const name = t(CORE_NAMES[type]?.id ?? type, CORE_NAMES[type]?.label ?? type);
const problem = CORE_DESIGN_PROBLEMS[design?.problem];
return problem
? t('templates.coreDesign.problemItem', '{name} ({reason})', {
name,
reason: t(problem.id, problem.label),
})
: name;
};
const checkedAt = broken
.map(([, design]) => design?.checkedAt)
.filter((value) => typeof value === 'string' && !Number.isNaN(Date.parse(value)))
.sort()
.pop();

return (
<Box marginBottom={6}>
<Notice
Expand All @@ -65,12 +105,16 @@ export const CoreDesignAlert = ({ enabled }) => {
{t(
'templates.coreDesign.staleBody',
'{names}: these emails fail until the template is available again and synced, or until you switch back to the Magic Mail designer.',
{
names: broken
.map(([type]) => t(CORE_NAMES[type]?.id ?? type, CORE_NAMES[type]?.label ?? type))
.join(', '),
}
{ names: broken.map(describe).join(', ') }
)}
{checkedAt ? (
<>
{' '}
{t('templates.coreDesign.checkedAt', 'Last checked: {date}.', {
date: formatDateTime(checkedAt),
})}
</>
) : null}
</Notice>
</Box>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,18 @@ export const CoreDesignDialog = ({ coreEmail, design, templates, onClose, onSave
</Notice>
) : null}

{choice !== DESIGNER &&
selected?.usable &&
selected.provider === 'mailgun' &&
!selected.subject ? (
<Notice tone="warning" role="alert">
{t(
'templates.coreDesign.noSubject',
'This Mailgun template has no Subject header. Core emails sent with it fail; add a Subject header to the template at Mailgun and sync.'
)}
</Notice>
) : null}

{choice !== DESIGNER ? (
<>
<Flex direction="column" alignItems="stretch" gap={2}>
Expand Down Expand Up @@ -230,10 +242,15 @@ export const CoreDesignDialog = ({ coreEmail, design, templates, onClose, onSave
onCheckedChange={(value) => setFallback(value === true)}
disabled={saving}
>
{t(
'templates.coreDesign.fallback',
'If the provider template fails, send the Magic Mail designer version instead'
)}
{coreEmail?.type === 'admin-forgot-password'
? t(
'templates.coreDesign.fallbackAdmin',
'If the provider template fails, send the Strapi admin email instead'
)
: t(
'templates.coreDesign.fallback',
'If the provider template fails, send the Magic Mail designer version instead'
)}
</Checkbox>
<Box paddingTop={1} paddingLeft={6}>
<Typography variant="pi" textColor="neutral600">
Expand Down
Loading