Overview
Icon for Mailtrap

Mailtrap

Send transactional email via Mailtrap

mailtrap-medusa

Mailtrap Email API notification provider for Medusa. Requires Medusa 2.22 or a newer 2.x release.

Prerequisites

Install

npm install mailtrap-medusa

Configure

Add the provider to the Notification Module in Copy to clipboardmedusa-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 Copy to clipboard.env:

MAILTRAP_API_KEY=
MAILTRAP_FROM=

Copy to clipboardMAILTRAP_FROM must be an address on your verified domain. Only one provider can handle a channel, so remove Copy to clipboardnotification-local from the Copy to clipboardemail channel if it is configured.

Options

Option Required Description Copy to clipboardapi_key yes Mailtrap API token. Copy to clipboardfrom yes Default sender address. Copy to clipboardnotification.from overrides it. Copy to clipboardcategory no Default category for emails sent with Copy to clipboardcontent (not used for template emails).

Sending

With a Mailtrap template: Copy to clipboardtemplate is the template UUID and Copy to clipboarddata 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 Copy to clipboardcontent:

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.",
},
})

Copy to clipboardprovider_data

  • Copy to clipboardcategory: category of the email, up to 255 characters. Shown in Mailtrap Email Logs and Stats. Ignored for template emails, which carry their own category.
  • Copy to clipboardcustom_variables: map of string values, up to 1000 bytes in total. Shown in Mailtrap Email Logs.

Errors

A failed send throws Copy to clipboardFailed to send email with Mailtrap: <API message> and the notification is marked as failed.

License

MIT

You may also like

Browse all integrations

Build your own

Develop your own custom integration

Build your own integration with our API to speed up your processes. Make your integration available via npm for it to be shared in our Library with the broader Medusa community.

gift card interface

Ready to build your custom commerce setup?