npm package: @faraz1999/medusa-plugin-mailjet
Description: Mailjet notification provider for Medusa v2
Author: Faraz
Latest version: 2.0.0

# Mailjet Notification Provider for Medusa v2

A notification provider plugin that integrates [Mailjet](https://www.mailjet.com/) email service with Medusa v2.

## Installation

```bash
npm install medusa-plugin-mailjet
# or
yarn add medusa-plugin-mailjet
```

## Configuration

Add the Mailjet provider to your `medusa-config.ts`:

```typescript
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: "noreply@example.com",
              from_name: "Your Store",
              // Optional: for template debugging
              template_error_reporting: "Developer dev@example.com",
            },
          },
        ],
      },
    },
  ],
})
```

## Environment Variables

```env
MAILJET_API_KEY=your_mailjet_api_key
MAILJET_API_SECRET=your_mailjet_api_secret
```

## Usage

### With Mailjet Templates

```typescript
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: "customer@example.com",
  channel: "email",
  template: "12345", // Mailjet template ID
  data: {
    variables: {
      first_name: "John",
      order_id: "ORD-001",
      // ... other template variables
    },
  },
})
```

### With Raw HTML

```typescript
await notificationService.createNotifications({
  to: "customer@example.com",
  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

```typescript
await notificationService.createNotifications({
  to: "customer@example.com",
  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@example.com") |

## 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