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

coins-mail

v4.0.7-1

Published

HTML and text email templates for COINS.

Downloads

27

Readme

HTML and text email templates for COINS.

Example

Create Mail

The createMail is coins-mail’s chief export. It expects a configured Bookshelf.js model:

const knex = require('knex')({
  /* DB config ... */
});
const bookshelf = require('bookshelf')(knex);
const createMail = require('coins-mail').createMail;

const MyMailModel = bookshelf.Model.extend({
  tableName: 'my_table_name',
});

createMail(MyMailModel, options); // returns Promise

createMail returns a Promise. In the case of a single mail option, this is the result of calling save on a Bookshelf.js model. In the case of a collection of mail options, this is the result of invoking save on the Bookshelf collection.

Options:

options can be either a mail options object or a collection of these objects:

  • fromLabel (string): Added to the from_label column. This is typically the name of application sending the email.
  • recipients (string or array of strings): Single recipient email address or a collection of email addresses.
  • replyTo (string): Email address to use in the email’s 'reply to' field.
  • subject (string): Email’s subject field.
  • templateLocals (object): Hash to pass to getTemplate. The keys/values depend on the email template in use (see templateName).
  • sendTime (string, defaults to Date.now()): Time to send the email.
  • templateName (string, defaults to “default“): Name of email template to use.

Single email

  createMail(MyMailModel, {
    fromLabel: 'Test Application',,
    recipients: [
      '[email protected]',
      '[email protected]',
      '[email protected]',
      // ...
    ],
    replyTo: '[email protected]',
    sendTime: Date.now() + 24 * 60 * 60 * 1000,
    subject: 'Test Subject',
    templateLocals: {
      html: {
        myHtmlTemplateVar: 'value',
      },
      text: {
        myTextTemplateVar: 'value',
      },
    },
    templateName: 'my-template',
  })
    .then(savedModel => console.log(savedModel))
    .catch(error => console.error(error));

Multiple emails


createMail(MyMailModel, [{
  fromLabel: 'Test Application 1',
  recipients: '[email protected]'
  replyTo: '[email protected]',
  subject: 'Test Subject 1',
  templateLocals: // ...
}, {
  fromLabel: 'Test Application 2',
  recipients: '[email protected]'
  replyTo: '[email protected]',
  subject: 'Test Subject 2',
  templateLocals: // ...
}, {
  fromLabel: 'Test Application 3',
  recipients: '[email protected]'
  replyTo: '[email protected]',
  subject: 'Test Subject 3',
  templateLocals: // ...
}])
  .then(savedModels => {
    savedModels.forEach(savedModel => console.log(savedModel));
  })
  .catch(error => console.error(error));

Template

const getTemplate = require('coins-mail').getTemplate;

getTemplate({
  html: {
    myHtmlTemplateVar: '<h1>Hi!</h1> <p>Insert this html…</p>',
  },
  text: {
    myTextTemplateVar: 'Alternative!\n\nFor the text version…',
  },
}, (error, result) => {
  if (error) {
    console.error(error);
  } else {
    console.log('HTML:', result.html);
    console.log('Text:', result.text);
  }
});

getTemplate also returns a Promise:

getTemplate(myLocals)
  .then(result => {
    console.log('HTML:', result.html);
    console.log('Text:', result.text);
  })
  .catch(error => console.error(error));

License

MIT. See LICENSE for details.