From 9dd8802e419325b213786144df9009e6c4fee489 Mon Sep 17 00:00:00 2001 From: PilsY Date: Sun, 16 Nov 2014 06:29:10 +1000 Subject: [PATCH] feat(mailer): Added basic mailer utility --- lib/utils/mailer.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/utils/mailer.js b/lib/utils/mailer.js index 55ffc73..3c5d3c6 100644 --- a/lib/utils/mailer.js +++ b/lib/utils/mailer.js @@ -1,9 +1,13 @@ var Promise = require( 'bluebird' ) , config = require( 'config' ) - , sendgrid = require( 'sendgrid' )( config.sendgrid.apiUser, config.sendgrid.apiKey ); + , sendgrid; -module.exports = { +module.exports = { send: function( payload ) { + if ( !sendgrid ) { + sendgrid = require( 'sendgrid' )( config.sendgrid.apiUser, config.sendgrid.apiKey ); + } + return new Promise( function( resolve, reject ) { sendgrid.send( payload, function( err, res ) { if ( !err ) {