Вышел Модуль интеграций 2.0 для MedusaЧитать анонс
E

Email templates plugin

Manage transactional email templates from Medusa Admin and send them through Medusa Cloud, Resend or Mailgun.

npm install @agilo/medusa-email-templates-plugin
Категория
Создано
Версия
1.1.0
Последнее обновление
3 дня назад
Ежемесячные загрузки
Загрузка данных

Medusa Email Templates Plugin

npm version npm license Node.js

Edit transactional emails and manage delivery from Medusa Admin. The plugin includes a visual editor, ready-to-edit emails, three built-in delivery providers (Medusa Cloud, Resend, and Mailgun), and a local preview transport for development.

Order confirmation email delivered to Gmail

Providers · Template editor · Built-in emails · Install · Credentials · Plugin options · Custom extensions

Choose a provider

Medusa Cloud, Resend, and Mailgun are included as delivery providers. One provider sends each email; the others keep their settings. In development, you can select Local Preview to write the rendered email to a local file instead.

ProviderSetup in AdminAvailability
Medusa CloudChoose Use. Credentials are managed by your Medusa Cloud project.Requires an application running on Medusa Cloud with its email configuration injected. Unavailable in local development.
ResendEnter a sender address, an optional reply-to address, and an API credential.Requires a Resend account and a key with sending access.
MailgunEnter a sending domain, its US or EU region, a sender address, an optional reply-to address, and an API credential.Requires a Mailgun account. A Domain Sending Key is sufficient; the plugin only calls the send endpoint.
Local PreviewChoose Use in development. No credentials are needed.Available only when . Sends are written as local HTML preview files instead of being delivered.

With Local Preview selected, the plugin logs a URL for each email in the Medusa server output. Open the URL in a browser or with your operating system's file opener. The preview file is written to the system temporary directory. The transport does not launch a browser or iOS Simulator automatically and is unavailable outside development.

Provider and template settings in Medusa Admin

To start sending:

  1. Open the provider's row menu and choose Configure. For Resend or Mailgun, fill in the sender and credential fields, then choose Save & activate.
  2. Use Send test from a delivery provider's row menu to check delivery to your own inbox. For Local Preview, Send test creates a preview file; its recipient is shown in the preview only.
  3. To switch to an available provider later, choose Use from its row menu.

Medusa Cloud needs no API key entered in Admin. Because the plugin owns the email channel, its built-in Cloud integration handles delivery in place of Medusa's automatically registered Cloud provider.

Switching providers uses credentials already available to the application. Adding server environment variables still requires updating your deployment environment; the stored API key option lets you manage provider keys in Admin once encryption is configured.

Visual editing

Editing an order confirmation email

Open a template from Settings → Email to edit its subject and body. The editor uses React Email Editor and provides:

  • Rich text and email layouts, including columns and repeating blocks for lists such as order items.
  • Template variables in the subject and body, with display formatting for money and dates.
  • A link picker for URL variables, including configured storefront links.
  • Preview and test send with example data, including unsaved edits.

Save your changes, check a test email in your inbox, then enable the template. Test sends work while a template is disabled, so you can review it before it handles live events.

Templates use Liquid for dynamic content. The plugin validates syntax when saving and generates a plain-text body from the rendered HTML when no separate text template is set.

Built-in emails

Each email has its own editable template and enable switch.

EmailTriggerTemplate key
Order confirmation, with items and totals
Admin invitation
Resent admin invitation
Admin password reset for an admin user
Customer password reset for a customer
Email verification code when the entity is an email address

The verification template handles an existing verification request event; your application still owns the flow that requests and checks verification codes.

If your application already has subscribers sending the same emails, adjust them before enabling these templates to avoid duplicate messages. Notifications that already include rendered content pass through the plugin's provider unchanged.

Install

Install the package in your Medusa application:

Add the plugin and its notification provider to your existing :

Keep your other modules, plugins, and notification providers. Medusa allows one notification provider per channel, so replace any existing provider with this one. If your application uses Medusa's local provider, retain it in the array too. The plugin registers its own modules automatically.

Run migrations, then restart your application:

npx medusa db:migrate

Open Settings → Email in Medusa Admin to configure delivery. Templates start disabled; enable each email when it is ready to send.

Security and credentials

Resend and Mailgun support two credential sources. Choose one in the provider configuration drawer:

SourceHow it works
Environment variableEnter the variable name, such as . The plugin stores that name and reads the key from the server environment when sending.
Stored API keyEnter the key in Admin. The plugin encrypts it with AES-256-GCM before storing it in the database.

Configuring provider credentials

Stored keys require on the server: 32 random bytes encoded as base64 or hex. For example, generate a base64 value with , then set it through your deployment's secret configuration. Without this encryption key, environment credentials remain available and stored API keys are disabled.

Keep the encryption key stable. If it changes, existing stored credentials become unusable and must be entered again. The Admin API returns credential status and the environment variable name where applicable; it never returns API keys or ciphertext.

Template rendering escapes values in HTML output. Liquid templates cannot read files or execute JavaScript, and parsing and rendering have resource limits.

Plugin options

Set these options in the plugin entry in to match your storefront and Admin routes:

OptionPurposeDefault
Base URL for customer links, such as .Unset
Customer password reset page.
Order details path; the order ID is appended.
Base Admin URL for invitations and admin password resets.The application's backend URL and Admin path

For example, a storefront with account pages can use:

Without , customer password reset emails are skipped. Order confirmations still send, but their order link is unavailable. Admin shows a warning when the storefront URL is missing.

Custom extensions

Developers can add application-specific email events and delivery providers through .

Use to register an event's template, recipient, context, and editor variables. Your Medusa subscriber calls when the event occurs. The registered template then appears alongside the built-in emails in Admin.

Event definitions can include snippets for the editor's slash menu. Typed variables support money and date formatting, URL selection, and lists with repeating content. The registry also exports and helpers for default template layouts.

Use with an implementation of to add another delivery provider while keeping existing templates and event definitions.

Compatibility

  • Medusa .
  • Node.js .

License

MIT. See LICENSE.