Building blocks for digital commerce
This module is a custom notification provider for Medusa.js using nodemailer
. It allows you to send emails via an SMTP server, making it easier to integrate email notifications into your Medusa projects.
- Send transactional emails through your SMTP server.
- Fully customizable and compatible with Medusa's notification system.
- Secure authentication using environment variables.
-
Install the necessary dependency:
npm install nodemailer
-
Copy the
smtp-notification
module into thesrc
directory of your Medusa project. -
Add the configuration to your
medusa-config.ts
file as shown below.
Update your medusa-config.ts
to include the smtp-notification
module:
modules: [
{
resolve: "@medusajs/medusa/notification",
options: {
providers: [
{
resolve: "./src/modules/smtp-notification",
id: "smtp-notification",
options: {
channels: ["email"], // Specify the channel for notifications
host: process.env.SMTP_HOST!, // SMTP server host
port: parseInt(process.env.SMTP_PORT!), // SMTP server port
secure: process.env.SMTP_SECURE === "true", // Use secure connection (true/false)
auth: {
user: process.env.SMTP_USER!, // SMTP user (email address or username)
pass: process.env.SMTP_PASS!, // SMTP password
},
},
},
],
},
},
];
Set up the following environment variables in your .env
file:
SMTP_HOST=<your_smtp_host> # e.g., smtp.gmail.com
SMTP_PORT=<your_smtp_port> # e.g., 587 (TLS) or 465 (SSL)
SMTP_SECURE=<true_or_false> # true for SSL, false for TLS
SMTP_USER=<your_smtp_username> # e.g., [email protected]
SMTP_PASS=<your_smtp_password> # e.g., your email password or app password
-
Ensure the module is correctly integrated as described above.
-
Use the notification system in Medusa to trigger emails via the
smtp-notification
provider. For example:await notificationModuleService.createNotifications({ to: order.email, channel: "email", template: "order-confirmation", data: { name: user.first_name, lastName: user.last_name, order_id: order.id, total: order.total, items: order.items, }, });
-
Customize your email templates as needed to enhance the user experience.
- Connection Errors: Ensure your SMTP host, port, and secure settings are correctly configured.
- Authentication Errors: Double-check your SMTP username and password. For Gmail users, ensure you've set up an App Password.
- Environment Variables Not Loading: Ensure you have a
.env
file and that it’s being loaded by your Medusa project.
If you encounter any issues or have suggestions for improvement, feel free to open an issue or submit a pull request.
This module is open-source and licensed under the MIT license.