summaryrefslogtreecommitdiffstats
path: root/lib/sendgrid.js
diff options
context:
space:
mode:
authorKyle Partridge <partkyle@gmail.com>2012-01-12 15:33:08 -0800
committerKyle Partridge <partkyle@gmail.com>2012-01-12 15:33:08 -0800
commit35ad93e288268f40a1ba20705879519750d24152 (patch)
treea37c4e0ceec05f10197dec4e3fb377c112c3c978 /lib/sendgrid.js
parent4f6c83b75a24cfba733e634f1a4df1758d9d0a87 (diff)
downloadsendgrid-nodejs-35ad93e288268f40a1ba20705879519750d24152.zip
sendgrid-nodejs-35ad93e288268f40a1ba20705879519750d24152.tar.gz
sendgrid-nodejs-35ad93e288268f40a1ba20705879519750d24152.tar.bz2
here
Diffstat (limited to 'lib/sendgrid.js')
-rw-r--r--lib/sendgrid.js31
1 files changed, 14 insertions, 17 deletions
diff --git a/lib/sendgrid.js b/lib/sendgrid.js
index eab1834..3ac715e 100644
--- a/lib/sendgrid.js
+++ b/lib/sendgrid.js
@@ -5,6 +5,8 @@ var https = require('https');
var nodemailer = require('nodemailer');
var _ = require('underscore');
+var Email = require('./email');
+
function SendGrid(credentials) {
this.api_user = credentials.api_user;
this.api_key = credentials.api_key;
@@ -17,7 +19,10 @@ function SendGrid(credentials) {
* @returns {Boolean}
*/
SendGrid.prototype.send = function(email, callback) {
- var post_data = this.getPostData(email.params || email);
+ if (email.constructor !== Email) {
+ email = new Email(email);
+ }
+ var post_data = this.getPostData(email);
var options = {
host: 'sendgrid.com',
path: '/api/mail.send.json',
@@ -28,6 +33,8 @@ SendGrid.prototype.send = function(email, callback) {
}
};
+ console.log(post_data)
+
var request = https.request(options, function(res) {
res.setEncoding('utf8');
res.on('data', function(chunk) {
@@ -51,18 +58,11 @@ SendGrid.prototype.smtp = function(email, callback) {
pass: this.api_key
};
- email = email.params || email;
+ if (email.constructor !== Email) {
+ email = new Email(email);
+ }
- nodemailer.send_mail({
- sender: email.from,
- to: email.to,
- subject: email.subject,
- body: email.text,
- html: email.html,
- headers: {
- "x-smtpapi": JSON.stringify(email['x-smtpapi'])
- }
- }, function(error, success) {
+ nodemailer.send_mail(email.toSmtpFormat(), function(error, success) {
callback.call(self, success, error);
});
@@ -73,12 +73,9 @@ SendGrid.prototype.getPostData = function(params) {
api_user: this.api_user,
api_key: this.api_key
}
- _(params).each(function(v, k) {
- if (_(v).isObject() && !_(v).isDate() && !_(v).isArray())
- v = JSON.stringify(v);
- data[k] = v;
- });
+ _.extend(data, params.toWebFormat());
+ console.log(data)
return querystring.stringify(data);
};