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

ses-template-mailer

v2.1.2

Published

Send HTML or plain text templates through Amazon Web Services Simple Email Service (SES) using Handlebars, Pug, EJS or Underscore.

Downloads

14

Readme

AWS Simple Email Service (SES) Template Mailer

Send HTML or plain text templates through Amazon Web Services Simple Email Service (SES) using Handlebars, Pug, EJS or Underscore. This is essentially a wrapper for ses.sendEmail.

Install

npm install --save ses-template-mailer

Usage

Email = require('ses-template-mailer')
email = new Email(options, credentials);
email.send(function(error, result){});

Options

| Name | Type | Description | -------------- |-----------------------|------ | options | Object or [Object] | Options are the same as AWS SES sendMail with the following additions. You may also pass an array of multiple email options. Multiple emails will be sent at 90 emails per second. | options.Message.TemplateData | Object | The data to parse the template with. This can also be set with email.templateData before calling send. | options.Message.TemplateType | String | The template engine to use. Must be one of the following: "handlebars", "pug", "ejs", "underscore". Handlebars is the default. This can also be set with email.templateType before calling send. | options.Message.Body.Html | String | The text email template. Should either be an html template string or a valid url eg: https://mybucket.s3.amazonaws.com/template.handlebars. Using an extension name like "handlebars", "pug", "ejs" or "underscore" will overwrite TemplateType. | options.Message.Body.Text | String | The text email template. Should either be a text template string or a valid url eg: https://mybucket.s3.amazonaws.com/template.handlebars. Using an extension name like "handlebars", "pug", "ejs" or "underscore" will overwrite TemplateType. If Message.Body.Text is null then a plain text email will be generated from the HTML. Note: Since Pug cannot parse plain text emails text is automatically parsed from html, be sure and nullify text property (Message.Body.Text=null) if you're using Pug. | credentials | Object | Config options are the the same as AWS Config. If you've already set up your conf globally you can leave this null

Properties

template (String)

The text email template. Should either be an html template string or a valid url eg: https://mybucket.s3.amazonaws.com/template.handlebars. Using an extension name like "handlebars", "pug", "ejs" or "underscore" will overwrite TemplateType.

templateData (Object)

The data to parse the template with. Refer to your desired templating engine for more details.

templateType (String)

The template engine to use. Must be one of the following: "handlebars", "pug", "ejs", "underscore". Handlebars is the default.

rateLimit (Number=90)

If sending multiple emails with with send delivery will be throttled ensure your don't go over your rate limit. Default: 90.

send (Function)

Dispatch emails

Parameters

| Name | Type | Description | -------------- |-----------------------|------ | callback | Function | A callback function. If no callback is given events are emitted. | callback.errors | [Error] | A collection of errors or null if there were no errors | callback.results | [Object] | The result of each send | callback.results.MessageId | String | The message id retuned from SES | callback.results.ResponseMetadata | Object | The response meta data retuned from SES | callback.results.ResponseMetadata.RequestId | String | The request id retuned from SES

Events

COMPLETE_EVENT

Event triggered when all emails have been processed and sent.

Parameters

| Name | Type | Description | -------------- |-----------------------|------ | errors | [Error] | A collection of errors or null if there were no errors | results | [Object] | The result of each send | results.MessageId | String | The message id retuned from SES | results.ResponseMetadata | Object | The response meta data retuned from SES | results.ResponseMetadata.RequestId | String | The request id retuned from SES

SEND_EVENT

Event trigged each time an email is sent.

| Name | Type | Description | -------------- |-----------------------|------ | result | Object | The result of each send | result.MessageId | String | The message id retuned from SES | result.ResponseMetadata | Object | The response meta data retuned from SES | result.ResponseMetadata.RequestId | String | The request id retuned from SES

ERROR_EVENT

Event trigger when an email failed to send.

| Name | Type | Description | -------------- |-----------------------|------ | error | Error | The send error

Examples:

Sending One Email (with callbacks)

Email = require('../lib/email')
email = new Email(
	{
		Destination: {
			BccAddresses: ['Jack Sprat <[email protected]>'],
			CcAddresses: ['Humpty Dumpty <[email protected]>'],
			ToAddresses: ['Peter Pumpkineater <[email protected]>']
		},
		Message: {
			Subject: {
				Data: 'Pumpkin Eater'
			},
			Body: {
					Html: {
						Data: '<div>{{peter}}, {{peter}} pumpkin eater, Had a wife but couldn't keep her; <a href="{{more}}">more</a></div>'
					},
					Text: {
						Data: '{{peter}}, {{peter}} pumpkin eater, Had a wife but couldn't keep her;'
					}
			},
			TemplateData: {name:'Peter', more: 'https://en.wikipedia.org/wiki/Peter_Peter_Pumpkin_Eater'},
			TemplateType: 'handlebars'
		},
		Source: '[email protected]',
		ReplyToAddresses: [ 'Nobody <[email protected]>'],
		ReturnPath: '[email protected]'
	}, {
		accessKeyId: 'my_aws_access_key',
		secretAccessKey: 'my_aws_secret_key',
		region: 'us-west-2'
	}

);

// Optional setup:
// email.template = '<div>{{peter}}, {{peter}} pumpkin eater, Had a wife but couldn't keep her; <a href="{{more}}">more</a></div>'
// email.templateData = {name:'Peter', more: 'https://en.wikipedia.org/wiki/Peter_Peter_Pumpkin_Eater'}
// email.templateType = 'handlebars'

email.send(function(err, data) {
	if (err)
		console.log(err, err.stack); // error
	else
		console.log(data); // success
}

Sending Multiple Emails (with events)

Email = require('../lib/email')
email = new Email([recipient1, recipient2, recipient3,]);
email.rateLimit = 200
email.on(Email.COMPLETE_EVENT, function(errors, results, data){
	console.log(results.length+" of "+data.length+" emails have been sent.")
});
email.on(Email.SEND_EVENT, function(result){
	console.log('email sent')
});
email.on(Email.ERROR_EVENT, function(error){
	console.log(error.stack)
});
email.send()

Tests

Make a copy of the test/conf.sample.coffee and update if necessary.

cp test/conf.sample.coffee test/conf.coffee // update conf.coffee
mocha test/email.coffee