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
- A Mailtrap account
- A verified sending domain
- An API token for that domain
Install
1npm install mailtrap-medusa
Configure
Add the provider to the Notification Module in Copy to clipboardmedusa-config.ts:
1234567891011121314151617181920module.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:
12MAILTRAP_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.
12345678910import { 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:
12345678910await 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 clipboard
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. - Copy to clipboard
custom_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.
Links
License
MIT
