npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

moleculer-mail

v2.0.0

Published

Send emails

Downloads

1,609

Readme

Moleculer logo

moleculer-mail NPM version

Send emails with nodemailer. Support localized templates.

Features

Install

$ npm install moleculer-mail --save

or

$ yarn add moleculer-mail

Usage

Send an HTML e-mail with Gmail

"use strict";

const { ServiceBroker } = require("moleculer");
const broker = new ServiceBroker();

// Load service
broker.createService(require("moleculer-mail"), {
    settings: {
        from: "[email protected]",
        transport: {
            service: 'gmail',
            auth: {
                user: '[email protected]',
                pass: 'yourpass'
            }
        }
    }
});

// Send an e-mail
broker.call("mail.send", { 
    to: "[email protected]", 
    subject: "Hello Friends!", 
    html: "This is the <b>content</b>!"
}).then(console.log);

Send an e-mail with mailgun with Cc & Bcc

// Load service
broker.createService(require("moleculer-mail"), {
    settings: {
        transport: {
            service: "mailgun",
            auth: {
                api_key: 'api12345',
                domain: 'domain.com'
            }
        }
    }
});

// Send an e-mail to some people
broker.call("mail.send", { 
    to: "[email protected]", 
    cc: "[email protected]",
    bcc: "[email protected]",
    subject: "Hello Friends!", 
    text: "This is a text only message!"
}).then(console.log);

Send an e-mail from template

// Load service
broker.createService(require("moleculer-mail"), {
    settings: {
        transport: {
            type: "sendmail"
        },
        templateFolder: "./email-templates",

        // Global data for templates
        data: {
            siteName: "My app"
        }
    }
});

// Send a welcome template
broker.call("mail.send", { 
    to: "[email protected]", 
    template: "welcome",
    language: "de",
    data: {
        name: "John Doe",
        username: "john_doe",
        verifyToken: "123456"
    }
});

Settings

| Property | Type | Description | | -------- | -----| ----------- | | from | String | Sender's default email address. Use it if missing from ctx.params | | transport | Object | Transport settings. Send to nodemailer.createTransporter | | htmlToText | Boolean | Enable html-to-text conversion | | templateFolder | String | Path to template folder | | fallbackLanguage | String | Fallback language folder in template | | data | Object | Global data for templates |

Transport options

Read more from transport options

Localized templates

The service support templates. You should follow the given folder structure:

<templateFolder>
... en (language)
...... welcome (template name)
.........subject.hbs (subject template for "en" language)
.........html.pub (html template for "en" language)
... hu (language)
...... welcome (template name)
.........subject.hbs (subject template for "hu" language)
.........html.pub (html template for "hu" language)

Actions

| Name | Params | Result | Description | | ---- | ------ | ------ | ----------- | | mail.send | Any field from here | Object | Send an email. | | mail.render | template,language,data | Object | Render a template. |

Test

$ npm test

In development with watching

$ npm run ci

License

The project is available under the MIT license.

Contact

Copyright (c) 2016-2022 MoleculerJS

@moleculerjs @MoleculerJS