Mailtrap Email API notification provider for Medusa. Requires Medusa 2.22 or a newer 2.x release.
- A Mailtrap account
- A verified sending domain
- An API token for that domain
npm install mailtrap-medusaAdd the provider to the Notification Module in medusa-config.ts:
module.exports = defineConfig({
modules: [
{
resolve: "@medusajs/medusa/notification",
options: {
providers: [
{
resolve: "mailtrap-medusa/providers/mailtrap",
id: "mailtrap",
options: {
channels: ["email"],
api_key: process.env.MAILTRAP_API_KEY,
from: process.env.MAILTRAP_FROM,
},
},
],
},
},
],
})And set the environment variables in .env:
MAILTRAP_API_KEY=
MAILTRAP_FROM=
MAILTRAP_FROM must be an address on your verified domain. Only one provider can handle a channel, so remove notification-local from the email channel if it is configured.
| Option | Required | Description |
|---|---|---|
api_key |
yes | Mailtrap API token. |
from |
yes | Default sender address. notification.from overrides it. |
category |
no | Default category for emails sent with content (not used for template emails). |
With a Mailtrap template: template is the template UUID and data holds the template variables.
import { Modules } from "@medusajs/framework/utils"
const notificationModuleService = container.resolve(Modules.NOTIFICATION)
await notificationModuleService.createNotifications({
to: "customer@example.com",
channel: "email",
template: "<template-uuid>",
data: { name: "Ada" },
})Or inline, with content:
await notificationModuleService.createNotifications({
to: "customer@example.com",
channel: "email",
template: "order-placed",
content: {
subject: "Your order",
html: "<p>Thanks for your order.</p>",
text: "Thanks for your order.",
},
})category: category of the email, up to 255 characters. Shown in Mailtrap Email Logs and Stats. Ignored for template emails, which carry their own category.custom_variables: map of string values, up to 1000 bytes in total. Shown in Mailtrap Email Logs.
A failed send throws Failed to send email with Mailtrap: <API message> and the notification is marked as failed.
MIT