• Сообщество
  • Блог
Документация
Плагины и интеграцииВсе расширения для Medusa от сообществаСтартерыЗапускайте проекты быстрее с готовыми решениями
ЭкспертыПодберите специалиста для разработки и развития вашего проекта на MedusaКейсыПосмотрите примеры Medusa в продакшене и успешные внедрения
Меч Moscow
Комплексная e-commerce платформа на Medusa для московского fashion-бренда

Меч Moscow · Fashion

Gorgo снижает затраты на адаптацию Medusa к локальным рынкам.

Мы разрабатываем плагины интеграции, осуществляем поддержку и развиваем сообщество разработчиков на Medusa в Telegram.

  • Ресурсы Medusa
  • Плагины и интеграции
  • Стартеры
  • Эксперты
  • Кейсы
  • Medusa Чат в Telegram
  • Medusa Новости в Telegram
  • Документация Gorgo
  • Связаться с нами
  • TelegramGitHub
Плагины
M

Mailer

Send UI-managed email notifications on Medusa store events via SMTP.

npm install @sam-ael/medusa-plugin-mailer
Категория
Уведомления
Создано
Sam-ael
Версия
0.2.0
Последнее обновление
2 недели назад
Ежемесячные загрузки
Загрузка данных
Звезды на Github
0
npmNPMGitHubGithub

Medusa Plugin Mailer

Send transactional emails from your Medusa v2 store when things happen — orders placed, shipments created, customers signed up, and more.

You pick which events matter, point them at HTML templates, and the plugin delivers over SMTP. Nothing is sent until you create an active mapping in the admin.

Medusa Website | Medusa Repository | Medusa Documentation

Features

  • Listen to a fixed set of Medusa events (orders, shipments, customers, returns, and optional custom events).
  • Map each event to a template, subject line, and variable paths in the admin UI.
  • Store mappings in the database — no seeds, no hidden defaults.
  • Ship generic HTML templates out of the box, or point to your own folder.
  • Send through SMTP with one or more “from” profiles.
  • Test sends from the admin without waiting for a real order.
  • Load order, fulfillment, and customer data automatically when resolving template variables.

Prerequisites

  • Node.js v20 or greater
  • A Medusa v2 backend
  • An SMTP provider (e.g. your host’s mail relay, Brevo, Amazon SES, Postmark, Gmail app password, etc.)
  • Optional: a storefront URL and logo URL for branding in templates

How to Install

  1. In your Medusa backend directory, install the plugin and Nodemailer:

    1npm install @sam-ael/medusa-plugin-mailer nodemailer
    2# or
    3yarn add @sam-ael/medusa-plugin-mailer nodemailer
  2. Add the plugin to your plugins list:

    1// medusa-config.ts
    2module.exports = defineConfig({
    3 // ...
    4 plugins: [
    5 // ...
    6 {
    7 resolve: "@sam-ael/medusa-plugin-mailer",
    8 options: {},
    9 },
    10 ],
    11})
  3. Set environment variables in (see Configuration for the full list):

    1MAILER_SMTP_HOST=smtp.example.com
    2MAILER_SMTP_PORT=587
    3MAILER_SMTP_USER=your-user
    4MAILER_SMTP_PASS=your-password
    5MAILER_SMTP_SECURE=false
    6
    7MAILER_FROM_NAME_1=My Store
    8MAILER_FROM_ADDRESS_1=no-reply@example.com
    9
    10MAILER_TEMPLATES_DIR=src/email_templates
    11
    12STORE_NAME=My Store
    13STORE_URL=https://www.example.com
  4. Run migrations so the mapping table exists:

    npx medusa db:migrate

    This creates an empty table. It does not insert any mappings for you.

  5. Start the backend and open the admin. You should see Mailer in the sidebar.

  6. Create at least one active mapping (event → template → variables). Until you do that, the plugin will not send mail for that event.


Configuration

Environment variables

VariableRequiredDescription
Yes (to send)SMTP host
No (default )SMTP port
Yes (to send)SMTP username
Yes (to send)SMTP password
NoSet for port 465
Yes (to send)Display name for sender profile 1
Yes (to send)From address for sender profile 1
… NoExtra sender profiles (pick by index in a mapping)
… No
RecommendedFolder of templates (relative to process cwd or absolute). Falls back to bundled templates if missing
RecommendedUsed as in templates
or RecommendedUsed as /
NoAbsolute image URL for
No (default )Parallel sends when several mappings match one event
NoSet for Nodemailer debug logs
NoEHLO / HELO hostname

If SMTP is incomplete, the plugin logs a warning and skips sending instead of crashing.

How events and mappings fit together

Think of two layers:

  1. What the plugin listens for — a fixed list of event names in the plugin code (). You cannot turn listening on/off in the database; you only map the ones you care about.
  2. What actually gets emailed — rows you create in Admin (or via API). Each row ties an event name to a template file, subject, variable map, recipient rule, and an active flag.

No active mapping ⇒ no email, even if the event fires.

Template placeholders

Templates use Go-style variables:

1<p>Hi {{ .first_name }},</p>
2<p>Order #{{ .display_id }} is confirmed.</p>

Always available without mapping:

PlaceholderSource
/ or
resolved recipient
mapping subject (after substitution)
(optional)
default text if you do not map it

Your mapping’s template variables object maps each name to a data path on the loaded entity, for example:

1{
2 "first_name": "customer.first_name",
3 "display_id": "display_id",
4 "total": "total"
5}

Unmatched placeholders are removed before the message is sent.

Recipient types

TypeBehavior
Prefer email from the order/customer graph
Prefer the order’s field
Use the fixed address on the mapping

Events the plugin listens to

These names are hardcoded. Map only the ones you need.

Orders

EventTypical use
Order confirmation
Order finished
Cancellation notice
Use sparingly (can be noisy)
“We’re packing your order”
Fulfillment canceled
Return started
Return received / refund note

Fulfillment

Prefer the Medusa core-flows names:

EventTypical use
Shipped + tracking
Delivered

Legacy aliases still listen if something emits them: , , .

Customers & RMA

Event
,
,
,

Optional custom events

Your app can emit these; the plugin will handle them if you add mappings. Payloads are not graph-hydrated — put the fields you need on the event data and map paths like → .

EventExample fields on
, , , ,
same
/ , , , ,
, , ,

Example emit from your backend:

1import { Modules } from "@medusajs/framework/utils"
2
3const eventBus = container.resolve(Modules.EVENT_BUS)
4
5await eventBus.emit({
6 name: "loyalty.points_credited",
7 data: {
8 email: "customer@example.com",
9 amount: 100,
10 balance: 500,
11 description: "Thanks for your order",
12 },
13})

What gets loaded for common events

Event patternHydrated data
(most)Full order (addresses, customer, items, totals, …)
Order via
/ Fulfillment + linked order (including tracking labels when present)
Custom loyalty / wallet / membershipEvent payload only

Bundled templates

The package ships plain, unbranded HTML under . Use them as-is or copy them into your and redesign.

Template fileGood starting point for
Alternate order confirmation
Returns / refunds
Email confirmation flows
Account removal
/ Loyalty custom events
/ Wallet custom events
Membership custom event
/ Free-form messages

Brand with and optional . Regenerate the defaults from the plugin repo with:

node scripts/generate-bundled-templates.mjs

Suggested mapping examples

Order confirmation

  • Event:

  • Template:

  • Subject:

  • Recipient: Order email

  • Variables:

    NamePath

Shipment

  • Event:

  • Template:

  • Subject:

  • Variables:

    NamePath

Test the Plugin

  1. Run your Medusa backend:

    1npm run dev
    2# or
    3npx medusa develop
  2. Open Admin → Mailer and check that SMTP shows as configured.

  3. Create an active mapping for → (or your own template).

  4. Either:

    • Place a test order in a storefront / Store API, or
    • Use Send email in the Mailer admin with a test address and sample variables.
  5. Confirm the message arrives and that placeholders look correct.

If nothing arrives: check SMTP env vars, that the mapping is active, and that the event name matches the list above (for shipping, prefer ).


Admin API (optional)

Useful for automation or custom UIs. All routes require an authenticated admin user.

MethodPathPurpose
SMTP status and sender profiles
Template files and detected variables
List mappings
Create mapping
Update mapping
Delete mapping
Manual / test send

You can also trigger the same pipeline from code:

1import { sendEventEmailsWorkflow } from "@sam-ael/medusa-plugin-mailer/workflows"
2
3await sendEventEmailsWorkflow(container).run({
4 input: {
5 event_name: "order.placed",
6 event_data: { id: orderId },
7 },
8})

Troubleshooting

What you seeWhat to check
No emails everSMTP env incomplete; Admin still says not configured
Event fires, no emailNo active mapping for that exact event name
Shipment email never sendsMap , not only older fulfillment aliases
Empty fields in the bodyVariable path wrong for that event’s data shape
Wrong “to” addressGuest orders use order email; adjust recipient type
Two emails for one actionAnother subscriber in your app is also sending — turn one off

Develop this repository

1yarn install
2yarn build # produces .medusa/server
3yarn typecheck
4yarn test

Peer dependencies should match your host Medusa version as closely as practical.


Additional Resources

  • Medusa documentation
  • Medusa events & subscribers
  • Medusa plugins
  • Nodemailer

License

MIT

Еще в этой категории

Посмотреть все
Уведомления
Nodemailer logo

Nodemailer

От Perseides

Отправляйте email-уведомления через Nodemailer (SMTP)

Загрузка данных
npm
Уведомления
Mailgun logo

Mailgun

От Webbers

Отправляйте и управляйте уведомлениями по электронной почте

Загрузка данных
GitHubnpm
Уведомления
Postmark logo

Postmark

От Bram-hammer

Транзакционные письма через Postmark

Загрузка данных
GitHubnpm

Еще от этого автора

Посмотреть все
Платежи
P

Payu

От Sam-ael

PayU India payment gateway integration for Medusa v2 with redirect flow.

Загрузка данных
GitHubnpm
Уведомления
W

Whatsapp

От Sam-ael

Send WhatsApp Business template messages on Medusa store events.

Загрузка данных
GitHubnpm
Доставка
S

Shiprocket

От Sam-ael

Shiprocket India fulfillment and live rates provider for Medusa v2.

Загрузка данных
GitHubnpm