Skip to content

Instantly share code, notes, and snippets.

@facultymatt
Last active December 23, 2015 06:19
Embed
What would you like to do?
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)

https://github.com/andris9/Nodemailer

Node Notifier

https://github.com/madhums/node-notifier

This is from the guy that insipired mean.io'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.

Drywall.io Mail Setup

I find the drywall.io 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.
https://github.com/jedireza/drywall/blob/master/utilities/sendmail.js

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