summaryrefslogtreecommitdiffstats
path: root/lib/sendgrid.js
diff options
context:
space:
mode:
authorLeigh Martell <leigh@goinstant.com>2013-09-19 00:40:22 -0300
committerscottmotte <scott@scottmotte.com>2013-10-29 15:36:14 -0700
commitbea9e704ed9d7b157cd3f9b4f015135bf73b0443 (patch)
tree29b6eca1ab8bf7e3f8603baa9cbb87512d2f657b /lib/sendgrid.js
parentf464b5ebb3eeacaf0141999f490ca3c535566117 (diff)
downloadsendgrid-nodejs-bea9e704ed9d7b157cd3f9b4f015135bf73b0443.zip
sendgrid-nodejs-bea9e704ed9d7b157cd3f9b4f015135bf73b0443.tar.gz
sendgrid-nodejs-bea9e704ed9d7b157cd3f9b4f015135bf73b0443.tar.bz2
added lodash; fix jshint errors; added jshint; updated package.json
Diffstat (limited to 'lib/sendgrid.js')
-rw-r--r--lib/sendgrid.js38
1 files changed, 24 insertions, 14 deletions
diff --git a/lib/sendgrid.js b/lib/sendgrid.js
index d0b3375..6014277 100644
--- a/lib/sendgrid.js
+++ b/lib/sendgrid.js
@@ -24,7 +24,7 @@ var Sendgrid = function(api_user, api_key, options) {
}
web.apply( this, arguments );
- }
+ };
/*
* Sends an email via web and returns true if the
@@ -35,8 +35,8 @@ var Sendgrid = function(api_user, api_key, options) {
* @param {Function} callback A function to call when the processing is done.
* This parameter is optional.
*/
- var web = function(email, callback) {
- var callback = callback || function() { };
+ var web = function(email, cb) {
+ var callback = cb || function() { };
if (email.constructor !== Email) {
email = new Email(email);
}
@@ -55,15 +55,15 @@ var Sendgrid = function(api_user, api_key, options) {
* @param {Function} callback A function to call when the processing is done.
* This parameter is optional.
*/
- var smtp = function(email, nodeMailerOptions, callback) {
+ var smtp = function(email, nodeMailerOptions, cb) {
// Support a callback without nodeMailerOptions
- if (! callback && typeof nodeMailerOptions === "function") {
+ if (! cb && typeof nodeMailerOptions === "function") {
callback = nodeMailerOptions;
nodeMailerOptions = null;
}
- var callback = callback || function() { };
+ var callback = cb || function() { };
if (email.constructor !== Email) {
email = new Email(email);
@@ -108,6 +108,12 @@ var Sendgrid = function(api_user, api_key, options) {
form['api_key'] = api_key;
var reqForm = req.form();
+
+ var _reqFormAppend = function(field, value) {
+ console.log('fields', field, value);
+ reqForm.append(field, value);
+ };
+
for (var field in form) {
var value = form[field];
if (value && value.filename) {
@@ -118,11 +124,12 @@ var Sendgrid = function(api_user, api_key, options) {
} else {
try {
if(!Array.isArray(value)){
- reqForm.append(field, value);
+ //reqForm.append(field, value);
+ _reqFormAppend.bind(this)(field, value);
}else{
- value.forEach(function(each){
- reqForm.append(field, each);
- });
+ console.log('field', field, value);
+ value.forEach(_reqFormAppend.bind(this, field));
+
}
} catch(err) {}
}
@@ -133,13 +140,14 @@ var Sendgrid = function(api_user, api_key, options) {
// SMTP settings
var smtp_settings = {
host: "smtp.sendgrid.net",
- port: parseInt(_this.port),
+ port: parseInt(_this.port, 10),
requiresAuth: true,
auth: {
user: api_user,
pass: api_key
}
- }
+ };
+
if (smtp_settings.port == 465) {
smtp_settings['secureConnection'] = true;
}
@@ -152,13 +160,15 @@ var Sendgrid = function(api_user, api_key, options) {
_.extend(smtpParams, nodeMailerOptions);
}
- smtpTransport.sendMail(smtpParams, function(error, response) {
+ smtpTransport.sendMail(smtpParams, function(error) {
+ //Returns: error, response; response unused
+
smtpTransport.close();
if(error) { return callback(new Error(error.message), null);}
return callback(null, {'message': 'success'});
});
- }
+ };
/*