Skip to content

Nik0di3m/medusa-smtp-notification-provider

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

Medusa logo

Medusa

Building blocks for digital commerce

PRs welcome! Product Hunt Discord Chat Follow @medusajs

SMTP Notification Provider for Medusa.js

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.

Features

  • Send transactional emails through your SMTP server.
  • Fully customizable and compatible with Medusa's notification system.
  • Secure authentication using environment variables.

Installation

  1. Install the necessary dependency:

    npm install nodemailer
  2. Copy the smtp-notification module into the src directory of your Medusa project.

  3. Add the configuration to your medusa-config.ts file as shown below.

Configuration

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
            },
          },
        },
      ],
    },
  },
];

Environment Variables

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

How to Use

  1. Ensure the module is correctly integrated as described above.

  2. 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,
      },
    });
  3. Customize your email templates as needed to enhance the user experience.

Troubleshooting

  • 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.

Contributing

If you encounter any issues or have suggestions for improvement, feel free to open an issue or submit a pull request.

License

This module is open-source and licensed under the MIT license.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published