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
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
## [Unreleased]

### Added

* **provider templates:** SendGrid dynamic templates and Mailgun templates (domain and account level) appear read-only under **Email Templates → Provider templates** as soon as a SendGrid or Mailgun account exists. Sync reads them with the stored account key (never writes to the provider), follows the providers' pagination, uses the EU hosts for EU accounts, and refreshes itself when the list is older than 10 minutes. A template whose remote id disappears but whose name still exists on the account (a database moved to another environment) is matched by name.
* **provider templates:** preview dialog with a sandboxed preview, the detected variables, a code example, a test send (to your own admin address by default, with the same sample values as local templates), an optional local fallback template, and **Copy as Magic Mail template** (HTML copy; Handlebars blocks become Mustache sections and anything that does not carry over is listed).
* **sending:** `send({ to, providerTemplate: '<provider>:<slug>', data })` sends a synced template. The same `data` object that local templates render with Mustache is sent as SendGrid `dynamic_template_data` or Mailgun `t:variables`, converted to plain JSON (dates as ISO strings, no functions, no cycles) and checked against the provider limits (Mailgun: 16 KB for all send options; Magic Mail bounds template data to 1 MB). Routing, rules, failover, quotas and logs work as before, but only between accounts that have the template. Strict by default: a missing template or a provider refusal is a clear error; a local fallback template is sent only when it is configured and no provider accepted the message. The log stores the template key and variable names, never the values.
* **core emails:** password reset and email confirmation can use a provider template (**Core emails → Design**). Magic Mail sends the familiar users-permissions names (`URL`, `TOKEN`/`CODE`, `USER`, `SERVER_URL`, `ADMIN_URL`) plus `url` (the finished link), `baseUrl`, `serverUrl`, `adminUrl`, `user`, `token`/`code` and `meta` (`templateKey`, `payloadVersion: 1`, `coreEmailType`). `USER` contains only `id`, `email`, `username`, `firstname`, `lastname`. Optional fallback to the Magic Mail designer version. A red notice on the Core emails tab and the dashboard names core emails whose template is not available.
* **templates:** **Convert for SendGrid or Mailgun** in the code snippets dialog turns a local template's Mustache logic into Handlebars for upload at the provider.
* **admin API:** `GET /magic-mail/provider-templates`, `POST /magic-mail/provider-templates/sync`, `GET /magic-mail/provider-templates/:key`, `POST /magic-mail/provider-templates/:key/test-send`, `PUT /magic-mail/provider-templates/:key/settings`, `POST /magic-mail/provider-templates/:key/copy`, `GET /magic-mail/designer/templates/:id/provider-html`, `GET /magic-mail/designer/core-designs`, `PUT /magic-mail/designer/core/:coreEmailType/design`. Existing permissions: `read` (sync is read-only at the provider and rate limited), `test-send`, `manage`; the core-email routes also need the users-permissions email-template permissions.

### Security

* Provider ids are never accepted from callers, only synced keys. The public Content API send routes do not accept `providerTemplate`.
* Template previews render in a sandboxed iframe without scripts. Provider requests go only to the fixed SendGrid and Mailgun hosts, with timeouts and response size limits; paging URLs from the provider are never requested directly.

### Migration

* Provider templates: nothing to do. A new collection `magic_mail_provider_templates` is created on start; nothing changes for accounts without SendGrid or Mailgun. Sends without a provider template are byte-identical to 4.7.0 (golden payload tests). Provider-template sends are not queued in the outbox in this release.
* To sync SendGrid templates, the SendGrid key also needs **Template Engine → Read Access** (sending alone needs only **Mail Send**).

### Verification

* SendGrid: tested live against the real SendGrid API on 2026-11-18, every send in sandbox mode: template sync with pagination, variable detection and preview, template sends, unknown and malformed template ids, the 1 MB data bound, and the template life cycle with temporary templates (no version, a first and a second active version, deleted and re-created under the same name, deleted for good). Temporary objects were deleted afterwards. The EU host could not be tested live (no EU subuser).
* Mailgun: verified against Mailgun's official OpenAPI specification and with tests, but not yet against the live Mailgun API. Please report anything unexpected.

# [4.7.0](https://github.com/Schero94/Magic-Mail/compare/v4.6.3...v4.7.0) (2026-11-18)


Expand Down
38 changes: 28 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +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.** Signed SendGrid and Mailgun 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 or Mailgun: their templates appear read-only in MagicMail, with preview, test send 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.
- **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 Expand Up @@ -78,6 +79,10 @@ All screenshots show synthetic data (`example.test` addresses) on an isolated St

![Email templates: totals, the custom and core email tabs, and a table of four templates with ID, name, category, status and actions](https://raw.githubusercontent.com/Schero94/Magic-Mail/main/docs/site/img/readme/templates.webp)

**Provider templates**: with a SendGrid or Mailgun account, their templates appear under your own, with the provider, the change date there, the accounts that have them and their status.

![Provider templates: SendGrid and Mailgun templates with provider badge, key, change date at the provider, account and status under the local templates](https://raw.githubusercontent.com/Schero94/Magic-Mail/main/docs/site/img/readme/provider-templates.webp)

**Analytics**: totals and the delivery log with server-side search, delivery status, opens and clicks per email.

![Analytics: sent, opened, clicked and bounced totals and the delivery log with recipient, subject, status, template, time, opens and clicks](https://raw.githubusercontent.com/Schero94/Magic-Mail/main/docs/site/img/readme/analytics.webp)
Expand Down Expand Up @@ -159,20 +164,33 @@ await strapi.plugin('magic-mail').service('email-router').send({
// → { success: true, accountUsed: 'Transactional SMTP', messageId: '<…>', emailId: '…' }
```

All send options, attachments, unsubscribe headers, provider setup, routing rules and templates: [Sending guide](https://github.com/Schero94/Magic-Mail/blob/main/docs/sending.md). HTTP routes: [API reference](https://github.com/Schero94/Magic-Mail/blob/main/docs/api.md).
Designed your email in SendGrid or Mailgun? Send the synced template with the same data a MagicMail template gets (only accounts that have the template send it):

```javascript
await strapi
.plugin('magic-mail')
.service('email-router')
.send({
to: 'customer@example.com',
providerTemplate: 'sendgrid:welcome-email', // key shown in Email Templates → Provider templates
data: { name: 'Ada', user: { email: 'customer@example.com' } },
});
```

All send options, attachments, unsubscribe headers, provider setup, routing rules, templates and [provider templates](https://github.com/Schero94/Magic-Mail/blob/main/docs/sending.md#provider-templates-sendgrid-mailgun): [Sending guide](https://github.com/Schero94/Magic-Mail/blob/main/docs/sending.md). HTTP routes: [API reference](https://github.com/Schero94/Magic-Mail/blob/main/docs/api.md).

## Permissions

MagicMail registers six admin actions under **Settings → Administration Panel → Roles → Plugins → MagicMail**:

| Action | Grants |
| --------------------------------- | --------------------------------------------------------------------------------------------------------------- |
| `plugin::magic-mail.access` | The MagicMail menu entry and page. No API access by itself |
| `plugin::magic-mail.read` | Read accounts, routing rules, templates, analytics and settings; render and export templates; the settings link |
| `plugin::magic-mail.manage` | Create, update and delete accounts, rules, templates, logs and settings; OAuth setup |
| `plugin::magic-mail.test-send` | Send test emails (account test, Strapi-service test, template test); 10 per minute per admin |
| `plugin::magic-mail.queue.read` | The Outbox tab and queue statistics (no mail content) |
| `plugin::magic-mail.queue.manage` | Retry, discard, mark as sent and delete outbox mails |
| Action | Grants |
| --------------------------------- | ------------------------------------------------------------------------------------------------------------------ |
| `plugin::magic-mail.access` | The MagicMail menu entry and page. No API access by itself |
| `plugin::magic-mail.read` | Read accounts, routing rules, templates, analytics and settings; render and export templates; the settings link |
| `plugin::magic-mail.manage` | Create, update and delete accounts, rules, templates, logs and settings; OAuth setup |
| `plugin::magic-mail.test-send` | Send test emails (account test, Strapi-service test, template and provider-template test); 10 per minute per admin |
| `plugin::magic-mail.queue.read` | The Outbox tab and queue statistics (no mail content) |
| `plugin::magic-mail.queue.manage` | Retry, discard, mark as sent and delete outbox mails |

Typical roles:

Expand Down Expand Up @@ -256,7 +274,7 @@ npm run verify
npm run verify:runtime
```

`npm run test:live` runs the opt-in suite against the real SendGrid and Mailgun APIs (SendGrid sandbox mode and Mailgun test mode, nothing is delivered; Mailgun bills test-mode messages). It reads `~/.config/magic-mail-live/.env` with `SENDGRID_API_KEY`, `SENDGRID_FROM`, `MAILGUN_API_KEY`, `MAILGUN_DOMAIN`, `MAILGUN_REGION`, `LIVE_TEST_RECIPIENT` and optionally `SENDGRID_REGION`, `SENDGRID_EU_API_KEY`, `SENDGRID_EU_FROM`, `MAILGUN_FROM`, `MAILGUN_EU_DOMAIN`, `MAILGUN_EU_API_KEY`; without the file every live test is skipped. Never commit that file.
`npm run test:live` runs the opt-in live suites against the real SendGrid and Mailgun APIs: the send paths (`tests/live/provider-send.live.test.js`), the provider-template flows (`tests/live/provider-templates.live.test.js`) and the rest of the SendGrid integration (`tests/live/sendgrid-account.live.test.js`: restricted API keys, template versions, read-only account checks; it creates temporary `magic-mail-live-*` API keys and templates and deletes them again, so its key needs full access). SendGrid runs in sandbox mode and Mailgun in test mode, so nothing is delivered (Mailgun bills test-mode messages). Credentials come only from `~/.config/magic-mail-live/.env` and are never printed. `LIVE_PROVIDERS` (environment variable or a line in that file) picks the providers: `sendgrid`, `mailgun` or `sendgrid,mailgun`; without it, every provider whose required variables are complete runs. Tests of a provider that is not selected are skipped with the reason. For SendGrid only: `LIVE_PROVIDERS=sendgrid npm run test:live`. Required per provider: SendGrid needs `SENDGRID_API_KEY`, `SENDGRID_FROM`, `LIVE_TEST_RECIPIENT` and, for the template suite, `SENDGRID_TEMPLATE_ID`; Mailgun needs `MAILGUN_API_KEY`, `MAILGUN_DOMAIN`, `MAILGUN_REGION`, `LIVE_TEST_RECIPIENT` and, for the template suite, `MAILGUN_TEMPLATE`. Optional: `SENDGRID_REGION`, `SENDGRID_EU_API_KEY`, `SENDGRID_EU_FROM`, `MAILGUN_FROM`, `MAILGUN_EU_DOMAIN`, `MAILGUN_EU_API_KEY`. Without the file, or when a selected provider misses a variable, the template suite fails with the file name and the missing variable names (the send suite reports those tests as skipped). It never runs in CI. Never commit that file.

`npm run test:admin` renders every admin entry point (the five sections of the MagicMail page with their dialogs, the template editor, the Plugin Settings page) inside `React.StrictMode` with the providers of the Strapi admin, in jsdom with a fake network. It fails on a mutation sent twice, a read repeated without aborting the first one, an interval, listener, connection or observer left after unmount, and any console error or warning. A separate CI job runs the same tests against React 19 for information only: the plugin's peer range is React 18, like the Strapi 5 admin.

Expand Down
27 changes: 25 additions & 2 deletions admin/src/pages/EmailDesigner/TemplateCodeSnippetsModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useCopyToClipboard } from '../../hooks/useCopyToClipboard';
import { useMagicMailIntl } from '../../hooks/useMagicMailIntl';
import { useReturnFocus } from '../../hooks/useReturnFocus';
import { buildCodeSnippets, snippetText } from './codeSnippets';
import { ConvertForProviderPanel } from './providerTemplates/ConvertForProviderPanel';
import {
AccentText,
CodeBlock,
Expand Down Expand Up @@ -38,9 +39,17 @@ const CodeTokens = ({ tokens }) =>
/**
* "Code snippets" dialog for one template.
*
* @param {{template: object|null, isOpen: boolean, onClose: () => void}} props
* With a SendGrid or Mailgun account (`providerEnabled`), an extra section
* converts the template for the provider ("Convert for provider").
*
* @param {{template: object|null, isOpen: boolean, onClose: () => void, providerEnabled?: boolean}} props
*/
export const TemplateCodeSnippetsModal = ({ template, isOpen, onClose }) => {
export const TemplateCodeSnippetsModal = ({
template,
isOpen,
onClose,
providerEnabled = false,
}) => {
const { t } = useMagicMailIntl();
const copy = useCopyToClipboard();
const [copiedKey, setCopiedKey] = useState(null);
Expand Down Expand Up @@ -187,6 +196,20 @@ export const TemplateCodeSnippetsModal = ({ template, isOpen, onClose }) => {
</Accordion.Item>
);
})}
{providerEnabled ? (
<Accordion.Item value="provider">
<Accordion.Header>
<Accordion.Trigger icon={() => <SecondaryTriggerIcon aria-hidden="true" />}>
{t('templates.convert.title', 'Convert for SendGrid or Mailgun')}
</Accordion.Trigger>
</Accordion.Header>
<Accordion.Content>
<Box padding={4}>
<ConvertForProviderPanel templateReferenceId={template.templateReferenceId} />
</Box>
</Accordion.Content>
</Accordion.Item>
) : null}
</Accordion.Root>
</ScrollableDialogBody>
<StyledModalFooter>
Expand Down
Loading
Loading