Send and manage email notifications
Send emails using Mailgun.
[!NOTE] If you use Mailgun's EU-hosted infrastructure, you need this url as the api_url: https://api.eu.mailgun.net
pnpm add @webbers/mailgun-notification-medusaAdd the provider to the module in your file:
1module.exports = defineConfig({2 projectConfig: {3 // ...4 },5 modules: [6 // ... other modules7 {8 resolve: "@medusajs/medusa/notification",9 options: {10 providers: [11 {12 resolve:13 "@webbers/mailgun-notification-medusa/providers/notification-mailgun",14 id: "notification-mailgun",15 options: {16 channels: ["email"],17 apiKey: process.env.MAILGUN_API_KEY,18 domain: process.env.MAILGUN_DOMAIN,19 from_email: process.env.MAILGUN_FROM,20 api_url: process.env.MAILGUN_API_URL, // Only required if using Mailgun's EU-hosted infrastructure21 templates: {22 "<template-name>": {23 subject: "<subject-function>",24 template: "<template-function>",25 },26 },27 default_locale: "nl",28 },29 },30 ],31 },32 },33 ]34})| Option | Description | Default |
|---|---|---|
| Your Mailgun API key | Required | |
| Your Mailgun domain | Required | |
| Your from email address | Required | |
| Your email template functions | Required | |
| The default locale for the emails | Required | |
| The API url of mailgun | Optional |
Create or update your file with the following variables:
1MAILGUN_API_KEY="<your-mailgun-api-key>"2MAILGUN_DOMAIN="<your-mailgun-domain>"3MAILGUN_FROM="<your-mailgun-from-email>"4MAILGUN_API_URL="<your-api-url>"To set up up your email templates two functions are required per template:
1import * as React from "react"2import {3 Html,4 Head,5 Preview,6 Body,7 Container,8 Heading,9 Text,10} from "@react-email/components"11
12export const getOrderPlacedTemplate = () => (13 <Html>14 <Head/>15 <Preview>Your order is confirmed</Preview>16 <Body>17 <Container>18 <Heading>Thanks for your order!</Heading>19 <Text>Order #12345 has been confirmed.</Text>20 <Text>Total: $59.99</Text>21 </Container>22 </Body>23 </Html>24)25
26export const orderPlacedSubject = (locale: string) => {27 switch (locale) {28 case "nl":29 return "Bestelling bevestigd"30 case "en":31 return "Order Confirmation"32 }33}1module.exports = defineConfig({2 projectConfig: {3 // ...4 },5 modules: [6 // ... other modules7 {8 resolve: "@medusajs/medusa/notification",9 options: {10 providers: [11 {12 resolve:13 "@webbers/mailgun-notification-medusa/providers/notification-mailgun",14 id: "notification-mailgun",15 options: {16 channels: ["email"],17 apiKey: process.env.MAILGUN_API_KEY,18 domain: process.env.MAILGUN_DOMAIN,19 from_email: process.env.MAILGUN_FROM,20 api_url: process.env.MAILGUN_API_URL, // Only required if using Mailgun's EU-hosted infrastructure21 templates: {22 "order-placed": {23 subject: orderPlacedSubject,24 template: getOrderPlacedTemplate,25 },26 },27 default_locale: "nl",28 },29 },30 ],31 },32 },33 ]34})In case you want to customize and test the plugin locally, refer to the Medusa Plugin docs.