@faraz1999/medusa-plugin-mailjet
v2.0.0
Published
Mailjet notification provider for Medusa v2
Downloads
82
Maintainers
Readme
Mailjet Notification Provider for Medusa v2
A notification provider plugin that integrates Mailjet email service with Medusa v2.
Installation
npm install medusa-plugin-mailjet
# or
yarn add medusa-plugin-mailjetConfiguration
Add the Mailjet provider to your medusa-config.ts:
import { defineConfig } from "@medusajs/framework/utils"
export default defineConfig({
// ... other config
modules: [
{
resolve: "@medusajs/medusa/notification",
options: {
providers: [
{
resolve: "medusa-plugin-mailjet",
id: "mailjet",
options: {
channels: ["email"],
api_key: process.env.MAILJET_API_KEY,
api_secret: process.env.MAILJET_API_SECRET,
from_email: "[email protected]",
from_name: "Your Store",
// Optional: for template debugging
template_error_reporting: "Developer [email protected]",
},
},
],
},
},
],
})Environment Variables
MAILJET_API_KEY=your_mailjet_api_key
MAILJET_API_SECRET=your_mailjet_api_secretUsage
With Mailjet Templates
import { INotificationModuleService } from "@medusajs/framework/types"
import { Modules } from "@medusajs/framework/utils"
// In a workflow or subscriber
const notificationService = container.resolve<INotificationModuleService>(
Modules.NOTIFICATION
)
await notificationService.createNotifications({
to: "[email protected]",
channel: "email",
template: "12345", // Mailjet template ID
data: {
variables: {
first_name: "John",
order_id: "ORD-001",
// ... other template variables
},
},
})With Raw HTML
await notificationService.createNotifications({
to: "[email protected]",
channel: "email",
data: {
subject: "Your Order Confirmation",
html: "<h1>Thank you for your order!</h1><p>Order ID: ORD-001</p>",
text: "Thank you for your order! Order ID: ORD-001",
},
})With Attachments
await notificationService.createNotifications({
to: "[email protected]",
channel: "email",
template: "12345",
data: {
variables: { order_id: "ORD-001" },
attachments: [
{
ContentType: "application/pdf",
Filename: "invoice.pdf",
Base64Content: "base64-encoded-content",
},
],
},
})Options
| Option | Type | Required | Description |
|--------|------|----------|-------------|
| api_key | string | Yes | Mailjet API Key |
| api_secret | string | Yes | Mailjet API Secret |
| from_email | string | Yes | Default sender email |
| from_name | string | Yes | Default sender name |
| template_error_reporting | string | No | Email for template error notifications (format: "Name [email protected]") |
Notification Data
| Field | Type | Description |
|-------|------|-------------|
| template_id | number | Mailjet template ID |
| subject | string | Email subject (for non-template emails) |
| html | string | HTML content (for non-template emails) |
| text | string | Plain text content |
| variables | object | Template variables |
| from_email | string | Override default from email |
| from_name | string | Override default from name |
| attachments | array | File attachments |
License
MIT
