nodemailer-mjml-sender
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

nodemailer-mjml-wrapper

"EmailSender" wrapper class around nodeemailer & MJML. Simply read from an mjml file, setup the transporter & sender, and voila!

The MJML template can take basic handlebars-style variables like {{ variable }}.

Example usage:

import path from "path";
import { EmailSender } from "nodemailer-mjml-wrapper";

async function sendEmail() {
    const mailer = new EmailSender();
    mailer.transporter
        .host("smtp.gmail.com")
        .secure(true)
        .account({
            user: "...",
            pass: "..."
        });

    const templatePath = path.join(process.cwd(), "templates");
    mailer.sender
        .from({
            name: "John Doe",
            email: "foo@bar.biz"
        })
        .to(["bar@foo.biz"])
        .subject("You have an email!")
        .template(path.join(templatePath, "email-template.mjml"), {
            variable: "Here is some dynamic variable that needs to be replaced",
        });

    const result = await mailer.send();
    console.log("Email sent:", result.messageId);
}

See the repository's test folder for a more complete example.


Use for good, comply with the CAN-SPAM Act, etc.

Package Sidebar

Install

npm i nodemailer-mjml-sender

Weekly Downloads

7

Version

1.0.1

License

MIT

Unpacked Size

52.3 kB

Total Files

18

Last publish

Collaborators

  • rewrking