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

mailer-template

v1.0.0

Published

Basic module to send mail based on mustache template

Downloads

2

Readme

mailer-template

build status

Basic node module to send mails based on templates. It depends on nodemailer to stablish connection with the mail server and mustache to render the mail body from the template.

You have top provide in a given directory a set of mail templates. For each temaplate at least two files need to be provided:

  • body: <template>.html.mst
  • options: <template>.json

where <template> is the name of the template.

You can also provide a body in text format in the file <template>.text.mst but this file is optional. If the file is not provided a text version is generated from the html using the package html-to-text

The file <template>.json should contain a json object with a set of options to be used while sending the email, this json object should contains at least a fiel subject with the template for the subject for the emil.

Installation

npm install mailer-template

Usage

Below you can find an example based on the following directory structure:

├── templates
│   └── mail
│       ├── confirm-password.html.mst
│       ├── confirm-password.json
│       ├── confirm-register.html.mst
│       └── confirm-register.json
└── use_mailer.js

The code for use_mailer.js is:

const mailer = require('mailer-template');
const path = require('path');

let connOptions = {
  sender: '[email protected]',
  dirTemplates: path.join(__dirname, 'templates/mail'),
  templates: [
    'confirm-register',
    'confirm-password'
  ]
};

if (process.env.MAIL_SERVICE) {
  connOptions = Object.assign(connOptions, {
    service: process.env.MAIL_SERVICE,
    user: process.env.MAIL_USER,
    password: process.env.MAIL_PASSWORD
  });
}
mailer.connect(connOptions)
  .then(() => mailer.sendMail('[email protected]', 'confirm-register', {
    href: 'https://site.domain.com/service?token=1234',
    userName: 'Name Perico'
  }))
  .then((infoSend) => {
    console.log('Preview URL: %s', mailer.getTestMessageUrl(infoSend));
    console.log('Body HTML =>');
    console.log(infoSend.message.html);
  });

Following are the content of the template files for confirm-register

confirm-register.json


{
    "subject": "Activate your account in The_Marvellouse_Account",
    "images": []
}

confirm-register.html.mst


<p>Hi {{userName}},</p>
<p>Thanks for signing up for The_Marvellouse_Service!</p>
<p>Please confirm your account at <a class=activate href="{{href}}">activate</a></p>

Tests & lint

npm run lint
npm test

Contributing

In lieu of a formal style guide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.