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

@momsfriendlydevco/email

v2.4.1

Published

MFDC standard wrapper library around Nodemailer

Downloads

17

Readme

@momsfriendlydevco/email

This module is a thin wrapper around the nodemailer module which loads its config from the locations specified in the Doop project.

Features:

Quickstart guide

If you're project is already setup with appropriate config (see Expected Config) you should just be able to call the module as follows:

var email = require('@momsfriendlydevco/email');

email()
	.send({
		to: '[email protected]',
		from: '[email protected]',
		subject: 'Plain email test via mfdc-email',
		text: 'Hello World',
	}, function(err, res) {
		// Do something with the result
	});

or using chainable methods:

var email = require('@momsfriendlydevco/email');

email()
	.to('Joe Random <[email protected]>')
	.subject('HTML chainable method email test via mfdc-email')
	.html('<p>Hello <b>World</b></p>')
	.send(function(err, res) {
		// Do something with the result
	});

Debugging

This module uses the Debug NPM. Simply set the environment variable to DEBUG=email (or any valid enabling glob) to see the output.

> DEBUG=email mocha test/mailgun.js
  Mailgun > Send
  email Email
  email =======================================
  email To: [email protected]
  email Subject: Plain email test via mfdc-email
  email -----------------
  email Hello Joe
  email ------ End ------
  email  +0ms

Using template views

Specifying the template property either as a key in the send() object or via the chainable .template() method, will specify the file on disk to be used when composing the email.

  • The type of email to send is determined by the file extension. .txt files are plain text and .html files are rich content.
  • All templates are rendered via Mustache with the parameters used taken from the templateParams option.
  • Mustache will automatically escape all variables. If you wish to use an unsecaped variable like a URL encase it in three levels of brackets rather than two e.g. {{{url}}}
var email = require('@momsfriendlydevco/email');

email()
	.to('Joe Random <[email protected]>')
	.subject('Password Recovery')
	.template(config.root + '/views/emails/password-recovery.txt')
	.templateParams({
		name: 'Joe Random',
		signoff: 'The MFDC team',
	})
	.send();

API

send(email, callback)

Dispatch an email. This is as functionally similar to the Nodemailer send() command as possible. Use this if lower level access is required. Returns a promise.

to, from, cc, bcc, subject, text, html()

All these methods are chainable:

var email = require('@momsfriendlydevco/email');

email()
	.to('[email protected]')
	.subject('something')
	.send();

attachments()

Attachments are an array of various inputs including inline file contents, paths to files or streams.

var email = require('@momsfriendlydevco/email');

email()
	.to('[email protected]')
	.subject('something')
	.attachments([
		{filename: 'inline-file.txt', content: 'Hello World!'},
		{filename: 'file-on-disk.txt', path: '/tmp/file-on-disk.txt'},
		{filename: 'file-from-stream.txt', fs.createReadSteram('/tmp/file-stream.txt')},
		{raw: '... mime encoding ...'},
	])
	.send();

See the NodeMailer attachment specification for more details.

params, templateparams

Populate the Handlebars replacement engine with a given object.

template

Specify a template file to read to obtain the email body. The file extension should be .txt or .html to determine the body type. Specify .params (or .templateParams) to populate the Handlebars replacement engine.

var email = require('@momsfriendlydevco/email');

email()
	.to('[email protected]')
	.subject('something')
	.template('/a/file/somewhere.txt')
	.params({username: 'joe'})
	.send();

init()

Reinitialize the mail transport and reset all defaults to the global values.

Expected Config

This module expects the following global.config / global.app.config variables to be specified to operate:

| Method | Key | Type | Description | |------------|----------------------------------|----------------|-------------| | All | email.enabled | Boolean | Temporarily disable the sending of email. If falsy this will message to the console and not actually send anything | | | email.method | String | What transport profile to use, see init() for details | | | email.{to,from,subject,cc,bcc} | String / Array | Default fields to use if unspecified | | | email.template | String | Read a template file and render it as the email content | | | email.inlineBase64 | Boolean | Automatically convert base64 blob to cid attachment + ref | | Mailgun | mailgun.apiKey | String | The API key for the Mailgun profile | | | mailgun.domain | String | The Mailgun domain, usually something like 'acme.com' (no 'http://' prefix or Mailgun suffix) | | Outlook365 | outlook365.user | String | User auth to send emails as via Outlook365 | | | outlook365.pass | String | User pass to send emails as via Outlook365 | | | smtp.host | String | Hostname to send via with SMTP | | | smtp.port | String | Port to send via with SMTP | | | smtp.secure | Boolean | Whether the connection should use TLS | | SMTP | smtp.user | String | User auth to send emails as via SMTP | | | smtp.pass | String | User pass to send emails as via SMTP |