medusa-plugin-nodemailer
A notification service based on Nodemailer & Handlebars templating engine.
Installation
To install, run the following command in your terminal:
npm install @lumot-eu/medusa-plugin-nodemailer
Add the following values to your medusa-config.js
file:
const plugins = [
{
resolve: "@lumot-eu/medusa-plugin-nodemailer",
options: {
fromAddress: process.env.MAIL_FROM_ADDRESS,
transport: {
host: process.env.MAIL_SMTP_HOST,
port: process.env.MAIL_SMTP_PORT,
auth: {
user: process.env.MAIL_SMTP_USER,
pass: process.env.MAIL_SMTP_PASS,
},
tls: {
rejectUnauthorized: false,
},
},
templatesDir: "email-templates",
layoutsDir: "email-templates/_layouts",
partialsDir: "email-templates/_partials",
defaultLayout: "default.hbs",
templateMap: {
"order.placed": {
name: "order.placed",
subject: "Order confirmation",
},
},
hbsHelpers: {
},
},
},
];
E-mail templates
Templates for each event should be placed in a sub-directory matching the name specified in the templateMap: eg. {templatesDir}/order.placed
. The sub-directory must contain two files: html.hbs
for the HTML version and txt.hbs
for the plain text version of the email.
If you'd like to try the example email templates, simply comment out templatesDir
, layoutsDir
, and partialsDir
in your configuration.
Custom events
To send notifications for custom events, include to
property in the event data payload. This property specifies the recipient e-mail address.