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

snailmail

v1.2.1

Published

Render templates into SES emails

Downloads

3

Readme

snailmail

Render mustache html templates into SES emails

Usage

/**
./templates/default.html

<p>Hello {{name}}</p>
**/

const Mailer = require('snailmail');

// configure mailer instance
const mailer = Mailer({
  templateDir: __dirname + '/emails',
  from: '[email protected]',
  key: 'AKIAXXXXXXXXXXXXXXXX',
  secret: 'xxxxxxxxxxxxxxxxxxxxxxxxxx',
  region: 'eu-west-1'
});

// send an email
mail.send({
  template: 'default'
  to: '[email protected]',
  subject: 'Test email',
  data: {
    name: 'Alice'
  }
}).then(() => console.log(`Message sent!`));

Mailer options

  • templateDir - a path to the directory where email templates are found
  • from - the sender/reply address for your emails
  • key - AWS accessKeyId for your SES account
  • secret - AWS secretAccessKey for your SES account
  • region - AWS region for your SES account
  • replyTo - (optional) - the value of the reply-to header of your email if distinct to the from address - Default undefined
  • ext - (optional) - the file extension of your email templates - Default .html
  • layout - (optional) - the path to a standard layout file to use for your email templates
  • attachments - (optional) - a map of files to include as attachments on all emails

Message options

  • to - the recipient address
  • template - the template used to render the message body. Should match the extensionless filename of one of the templates in your template directory
  • subject - the subject line of your message. This will also be passed through mustache.render, so can contain dynamic content
  • data - any dynamic data to be rendered into the subject or body of your message
  • attachments - (optional) - a map of files to include as attachments for this email

Layouts

By default your message templates will be sent exactly as they are defined in the template file. However, if you want to wrap your messages in a standard header/footer then you can define a layout file for your emailer instance.

Your layout will be passed a partial template message which it should include - as per the following example:

layout.html

<header>
  <h1>My header content</h1>
</header>
{{>message}}
<footer>
  <p>My footer content</p>
</footer>
const mailer = Mailer({
  templateDir: __dirname + '/emails',
  layout: __dirname + '/layout.html',
  // ...
});

Attachments

Attachments should be defined as a map of content ids and filenames.

const mailer = Mailer({
  // ...
  attachments: {
    myfile: '/path/to/my/file.png',
    myotherfile: '/path/to/my/other/file.png'
  }
});

An attachment included on the options passed to send will overwrite a default attachment if it has the same content id.

Embedded images

Images can be embeded in your emails by giving a src attribute of cid:<attachmentId>, where the id corresponds to the content id of one of your attachments.

<img src="cid:header" width="100" height="20" />
mailer.send({
  to: '[email protected]',
  subject: 'Important message',
  attachments: {
    header: '/path/to/my/file.png'
  }
});