MagicMail

Every Strapi email, through the right account

MagicMail is a free, MIT-licensed Strapi 5 plugin that sends every Strapi email through several SMTP and API accounts, with routing rules, quotas, failover that never sends a mail twice, and an outbox that retries what did not go out.

Your existing strapi.plugin('email') calls keep working. Accounts, rules, templates and the delivery log live in the Strapi admin.

Used by

Using MagicMail in production? Show your logo here

  • Strapi ^5.57.0
  • Node.js 22.12 to 26.x
  • npm, yarn and pnpm
  • MIT, no license key

npm version npm downloads CI build status License: MIT Strapi 5.57+ Documentation site

MagicMail email accounts in the Strapi admin: stat cards for emails today, total sent and active accounts, and a table of three SMTP accounts with priority, usage today against the daily limit, total sent and last use.

Is MagicMail the right fit?

Use it when

  • You send through more than one account or provider and want rules to pick one.
  • A failed account should hand over to the next without a mail going out twice.
  • Failed sends should be retried, with an outbox you can review in the admin.
  • You want templates, quotas and a delivery log inside Strapi.

Skip it when

  • You need channels other than email. MagicMail sends email only.
  • One provider through the Strapi email plugin is all you need.
  • Your project runs Strapi 4, or Strapi 5 older than 5.57.0.

Requirements

  • Strapi ^5.57.0 with @strapi/plugin-users-permissions
  • Node.js >=22.12.0 <=26.x.x
  • PostgreSQL, MySQL 8 or SQLite
  • MAGIC_MAIL_ENCRYPTION_KEY outside development and test

What you get

Everything lives in the Strapi admin under MagicMail: email accounts, routing rules, templates, analytics and the outbox, in five languages, light and dark.

Email accounts

Gmail, Microsoft 365 and Yahoo with OAuth 2.0, any SMTP server (optional DKIM), SendGrid, Mailgun, Brevo and Amazon SES. Hourly and daily quotas, priorities, a primary account and test sends. Credentials are encrypted with AES-256-GCM.

Provider templates

SendGrid, Mailgun, Brevo and Amazon SES templates appear read-only next to your own templates, with preview, test send and the same template data your code already passes. Routing, failover and logs stay in MagicMail.

Routing rules

Pick the account by email type, recipient, subject, template or a custom value, with a fallback account. Rules pointing to a missing or inactive account are flagged.

Failover that never doubles a mail

The next account is tried only when the error proves the provider did not accept the mail: a refused connection, an SMTP 4xx reply, HTTP 429 or 503. A connection lost after the message was sent stops the send instead.

Outbox with retries

Opt-in per send or for every failed send: 3 retries by default after 1, 5 and 15 minutes, idempotency keys, and an Outbox tab to retry, discard or mark uncertain mails as sent.

Delivery webhooks

Verified SendGrid, Mailgun, Brevo and Amazon SES (SNS) webhooks record bounces, complaints and deliveries on the delivery log, feed the suppression list and emit magic-mail.delivery.* events for other plugins.

Bounce monitoring

Reads bounce reports from SMTP, Gmail and Microsoft 365 mailboxes, marks the mail as bounced or deferred, and rejects typo and test domains before sending.

Templates

Visual designer (Unlayer) or plain HTML and text, Mustache variables, versions with restore, import and export, and the Users & Permissions reset and confirmation mails.

Analytics

A delivery log with server-side search, opens and clicks per email. Tracking keeps truncated IPs only and expires on a schedule you set.

Drop-in for the email service

strapi.plugin('email'), sendTemplatedEmail(), the admin password reset and the Users & Permissions mails are routed through MagicMail without code changes.

Install in a minute

Requires Node.js >=22.12.0 <=26.x.x, Strapi ^5.57.0 and @strapi/plugin-users-permissions (part of every default Strapi app).

  1. Install the package.

    Terminal
    npm install strapi-plugin-magic-mail
    # or: yarn add strapi-plugin-magic-mail / pnpm add strapi-plugin-magic-mail
  2. Enable it.

    config/plugins.js
    module.exports = () => ({
      'magic-mail': { enabled: true },
    });
  3. Set the encryption key (required outside development and test; keep it stable).

    Terminal
    node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"
    # .env
    MAGIC_MAIL_ENCRYPTION_KEY=<the generated value>
  4. Run npm run build and npm run develop, open MagicMail → Email Accounts, add an account and send a test to yourself.

Compatibility
MagicMail Strapi Node.js Databases
4.x ^5.57.0, acceptance host 5.63.0 >=22.12.0 <=26.x.x, CI on 22, 24 and 26 PostgreSQL, MySQL 8, SQLite. Several processes: PostgreSQL tested, MySQL not load-tested

The packed plugin installs with npm into a Strapi 5.63.0 project without plugin warnings (yarn 1 and pnpm were checked on Strapi 5.61). Upgrading? Read the migration notes.

Provider templates

Design in SendGrid, Mailgun, Brevo or Amazon SES, send through MagicMail. Nothing changes until an account of one of these providers exists.

  1. MagicMail reads the templates of SendGrid (dynamic templates), Mailgun (domain and account templates), Brevo and Amazon SES with the stored key (read-only), and refreshes the list when it is older than 10 minutes.
  2. Each template gets a stable key such as sendgrid:welcome-email. Open it for a sandboxed preview, its variables, a test send or a copy as a MagicMail template.
  3. Send it with the same data a local template gets: send({ to, providerTemplate: 'sendgrid:welcome-email', data }). Only accounts that have the template send it; a missing template is a clear error unless you chose a fallback template.
  4. Password reset and email confirmation can use a provider template too (Core emails → Design), with URL, TOKEN/CODE, a limited USER and a finished url.

Every request is checked in CI against the official SendGrid and Mailgun OpenAPI documents. A live suite runs the same flows against the real APIs in sandbox and test mode with maintainer test accounts.

Retries and the outbox

Off by default. Turn it on per send with queue: true, or for every failed send with Settings → MagicMail → Queue failed sends.

Server codequeue: true
await strapi.plugin('magic-mail').service('email-router').send(
  { to: 'user@example.com', subject: 'Welcome', html: '<p>Hello</p>' },
  { queue: true, idempotencyKey: 'signup-42:welcome' }
);
// { success: true, queued: true, status: 'pending', outboxId, emailId, ... }
What happens to a failed send with Queue failed sends on
Outcome Outbox The caller sees
No provider accepted it (SMTP 4xx, refused connection, HTTP 429 or 503) Pending, retried after 1, 5, 15 minutes { success: true, queued: true }
Every account over its quota Pending until the next quota hour, no retry used { success: true, queued: true }
The provider may have accepted it (lost connection after the data, HTTP 500) Uncertain, never re-sent automatically The original error, with magicMailOutboxId
Permanent refusal (SMTP 5xx, HTTP 400, invalid input) Not stored The original error

Queued mails are encrypted in the database and deleted when sent or discarded. Login and one-time-code mails should use queue: false or a notAfter; MagicMail never sends a queued mail after notAfter. Full outbox guide.

Bounce monitoring

Off by default. Turn it on per account in the wizard. MagicMail reads the bounce reports that land in the sending mailbox and updates the delivery log.

How each account type reports bounces
Account Read via Owner step
SMTP IMAP with the SMTP login Turn it on
Gmail / Google Workspace Gmail API or IMAP with app password Grant read access, or create an app password
Microsoft 365 Microsoft Graph Grant Mail.Read (admin consent in some tenants)
SendGrid, Mailgun Signed webhooks Save the webhook key
Brevo Webhook with the account's random token Add the webhook URL in Brevo
Amazon SES Amazon SNS messages with signature checks Subscribe the webhook to the SNS topic and save the topic ARN

Reports are matched by the original Message-ID. 5.x.x marks the mail as bounced, 4.x.x as deferred. Only reason codes are stored, never message content. Before sending, typo domains such as googelmail.com and reserved test domains are rejected. Bounce monitoring guide.

Running several instances

Railway replicas and pm2 cluster workers work on one database, without sticky sessions or Redis.

  • Quotas, rate limits, OAuth flows, webhook de-duplication and background jobs are coordinated through the database.
  • Every process runs an outbox worker. Mails are claimed with FOR UPDATE SKIP LOCKED on PostgreSQL, so no mail is claimed twice; a process killed while a provider had the mail leaves it uncertain, never re-sent.
  • Use the same APP_KEYS, MAGIC_MAIL_ENCRYPTION_KEY, MAGIC_MAIL_TRACKING_SECRET and MAGIC_MAIL_OAUTH_STATE_SECRET everywhere, and server.proxy.koa: true behind a proxy. Each process logs short secret fingerprints at startup to compare.

Setup guide with pm2 and Railway examples.

Configuration

Accounts, rules, templates and settings are managed in the admin. The plugin config only holds deployment choices; every key is optional and validated at startup.

Environment variables
Variable Purpose
MAGIC_MAIL_ENCRYPTION_KEY Credential and outbox encryption key, 32+ bytes. Required unless NODE_ENV is unset, development or test.
MAGIC_MAIL_ENCRYPTION_KEY_PREVIOUS Old key during a rotation (decrypt only).
MAGIC_MAIL_TRACKING_SECRET, …_PREVIOUS Tracking hash secret and old values that stay valid.
MAGIC_MAIL_OAUTH_STATE_SECRET OAuth state signing secret (default: derived from the encryption key).
Main plugin options (config/plugins.js)
Key Default Effect
contentApi.allowUserRoles false Let users-permissions roles call the send routes
quotaTimezone 'UTC' Time zone of the quota windows
tracking.eventRetentionDays 90 Delete open and click events after this many days
tracking.allowedLinkHosts [] Hosts that Content-API mails may click-track
rateLimit.store 'database' Shared counters; 'redis' or 'memory' optional
queue.worker true false keeps this process from sending queued mail
queue.backoffMs [60000, 300000, 900000] Waits before retry 1, 2 and 3
Set Strapi's server.url to your public https URL: OAuth redirect URIs and tracking links are built from it, and in production MagicMail never falls back to localhost. Every option is in the configuration reference.

Security and privacy

Each admin route requires an authenticated administrator plus plugin::magic-mail.read, .manage, .test-send, .queue.read or .queue.manage; .access only shows the menu entry.

  • Account credentials, OAuth tokens and queued mails are encrypted with AES-256-GCM. The browser only receives the placeholder ********.
  • The Content API send routes accept API tokens only, validate every field strictly and share 60 requests per minute per token across all instances.
  • HTML is sanitised, from is pinned to the sending account, headers are allowlisted, and file-path or URL attachments are rejected.
  • SMTP requires TLS 1.2 or newer with certificate checks. OAuth callbacks use a signed, single-use state with PKCE, bound to the admin who started the flow.
  • Bounce and complaint webhooks are verified with the provider signature and a one-hour window; replays are ignored.
  • Tracking stores IPs truncated to /24 or /48 and no location; events expire after 90 days. Authentication links are never tracked.

Found a vulnerability? Use private vulnerability reporting.

API

Content API routes live under /api/magic-mail; admin routes under /magic-mail use the admin session and the permissions above.

Content API
Method Path Purpose
POST /send Send through the router with all send options, optional queue (API token).
POST /send-message Simple email: recipients, subject, message or template (API token).
GET /track/open/:emailId/:recipientHash Open-tracking pixel (public).
GET /track/click/:emailId/:linkHash/:recipientHash Click redirect (public).
POST /webhooks/sendgrid/:accountId, /webhooks/mailgun/:accountId Signed bounce and complaint events.
RequestAPI token
curl -X POST https://cms.example.com/api/magic-mail/send \
  -H "Authorization: Bearer $MAGIC_MAIL_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ "to": "customer@example.com", "templateId": 100,
        "templateData": { "user": { "firstName": "Ada" } } }'
Response200
{ "success": true, "accountUsed": "Transactional SMTP",
  "messageId": "<…@example.com>", "emailId": "…" }

Admin routes cover accounts, OAuth, routing rules, templates and versions, analytics, the outbox and settings. The API reference lists every route with its permission and examples.

FAQ

Do I have to change my existing email code?

No. MagicMail wraps the provider of @strapi/email, so strapi.plugin('email').service('email').send(), the admin password reset and the Users & Permissions mails are routed through it.

Can a mail be delivered twice?

Not because of MagicMail's own retries. Failover moves on only when the provider provably did not take the mail, and uncertain mails wait for your decision in the Outbox tab.

What happens when no account can send?

Mails sent through the Strapi email service fall back to the email provider you configured before. The router service and the Content API return the error. With Queue failed sends on, a mail blocked only by quotas is retried in the next quota hour.

Do I need Redis for several replicas?

No. The database coordinates everything; Redis is optional for the rate limiter.

Does the visual editor contact a third party?

The Unlayer editor loads from editor.unlayer.com in the editor user's browser. The plain HTML and text editor works without it, and sending never needs it.

Is there a paid version?

No. MagicMail is MIT licensed with no license key, tiers or usage limits.

Releases and maintenance

Actively maintained. Releases are cut by semantic-release from Conventional Commits on main and published to npm with provenance.

Every pull request runs lint, format check, tests, build, export and server-bundle verification, npm pack --dry-run and a production audit on Node.js 22, 24 and 26.