diff options
author | scottmotte <scott@scottmotte.com> | 2013-07-11 21:22:15 +0000 |
---|---|---|
committer | scottmotte <scott@scottmotte.com> | 2013-07-18 20:26:38 +0000 |
commit | a24874ab53d88d3b218937b5d8d10d361ad016ef (patch) | |
tree | ce8f683fec916e5da81338b95ee3dc3991a87412 /lib/sendgrid.js | |
parent | a5c8718700ea3ded1b08584941d8864fdf879165 (diff) | |
download | sendgrid-nodejs-a24874ab53d88d3b218937b5d8d10d361ad016ef.zip sendgrid-nodejs-a24874ab53d88d3b218937b5d8d10d361ad016ef.tar.gz sendgrid-nodejs-a24874ab53d88d3b218937b5d8d10d361ad016ef.tar.bz2 |
This is a combination of 2 commits.
Adding tests for smtp. Tests hit real smtp server at the moment
Diffstat (limited to 'lib/sendgrid.js')
-rw-r--r-- | lib/sendgrid.js | 24 |
1 files changed, 9 insertions, 15 deletions
diff --git a/lib/sendgrid.js b/lib/sendgrid.js index 1814cbe..9635340 100644 --- a/lib/sendgrid.js +++ b/lib/sendgrid.js @@ -9,6 +9,10 @@ var mime = require('mime'); var Email = require('./email'); +var SMTP = "SMTP"; +if (process.env.NODE_ENV == "test") { + //SMTP = "STUB"; +} /* * Class for handling communications with SendGrid. * @@ -16,8 +20,8 @@ var Email = require('./email'); * @param {String} api_key The key credentials for SendGrid. */ function SendGrid(api_user, api_key) { - this.api_user = api_user; - this.api_key = api_key; + this.api_user = api_user; + this.api_key = api_key; } /* @@ -124,7 +128,7 @@ SendGrid.prototype.smtp = function(email, callback) { , cb = callback || function() { }; // SMTP settings - smtpTransport = nodemailer.createTransport("SMTP", { + smtpTransport = nodemailer.createTransport(SMTP, { service: 'SendGrid', auth: { user: this.api_user, @@ -136,7 +140,7 @@ SendGrid.prototype.smtp = function(email, callback) { smtpTransport.sendMail(email.toSmtpFormat(), function(error, response) { smtpTransport.close(); if(error) { - return cb(false, response); + return cb(false, error.data); } return cb(true, response); }); @@ -146,17 +150,7 @@ SendGrid.prototype.smtp = function(email, callback) { email = new Email(email); } - if (_.size(email.files) > 0) { - email.processFiles(function(success, message) { - if (success) { - send_smtp(); - } else { - cb(false, message); - } - }); - } else { - send_smtp(); - } + send_smtp(); }; /* |