Skip to content

Instantly share code, notes, and snippets.

Last active December 23, 2015 06:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save facultymatt/6593489 to your computer and use it in GitHub Desktop.
Save facultymatt/6593489 to your computer and use it in GitHub Desktop.
Node Email / notifier Best Practices

Emailer / Notifier Best Practices

  • Supports any protocol, ideally by just setting a config option or function.
  • Supports sendgrid, which is a Heroku based app, making it super simple to get running on develop.
  • Won't fail, or catches errors, if any variables are missing.
  • Checks for development and testing environments, and prevents email send (console.log instead)
  • REUSABLE! The library itself, and maybe even the template, should be resuable across projects.

Good Looking Approaches

NodeMailer (current best pick)

Node Notifier

This is from the guy that insipired's setup. All functionality is self contained - you simply call:

notifier.send('comment', options, function (err) {
  if (err) return console.log(err);
  console.log('Successfully sent Notifiaction!');

And notifier checks for the default email client, sets the template and options, handles environment settings such as disabling sending in development mode, and then sends the email.

It assumes you have a matching template for comment living in /templates, see example, but you can easily set config.tplPath or override the template function alltogether. Mail Setup

I find the project is a good goto project for learning an reference. While not modular enough to pull the code into our project, its woth looking at how they do it. Similar to notifier I believe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment