diff options
author | Kyle Partridge <partkyle@gmail.com> | 2012-01-13 16:28:12 -0800 |
---|---|---|
committer | Kyle Partridge <partkyle@gmail.com> | 2012-01-13 16:28:12 -0800 |
commit | 2fd759fa8136ce0123070a948fdb38255d9d7695 (patch) | |
tree | a3b649474e7aca6e3e9870201c93f44c10b3514e /lib/sendgrid.js | |
parent | 967d1766b1a3a52967e10f67c6c956b0749fc9d6 (diff) | |
download | sendgrid-nodejs-2fd759fa8136ce0123070a948fdb38255d9d7695.zip sendgrid-nodejs-2fd759fa8136ce0123070a948fdb38255d9d7695.tar.gz sendgrid-nodejs-2fd759fa8136ce0123070a948fdb38255d9d7695.tar.bz2 |
the post needs to be handled differently based on whether or not the request is multipart
Diffstat (limited to 'lib/sendgrid.js')
-rw-r--r-- | lib/sendgrid.js | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/lib/sendgrid.js b/lib/sendgrid.js index 4d039a3..cc1d98d 100644 --- a/lib/sendgrid.js +++ b/lib/sendgrid.js @@ -35,8 +35,9 @@ SendGrid.prototype.send = function(email, callback) { var options = { host: 'sendgrid.com', path: '/api/mail.send.json', - method: 'POST', + method: 'POST' }; + if (email.hasFiles()) { post_data = self.getMultipartData(email); var length = 0; @@ -63,9 +64,16 @@ SendGrid.prototype.send = function(email, callback) { }); }); - for (var key in post_data) { - request.write(post_data[key]); + // If the email has files, it will be a multipart request. + // TODO: make this feel less dirty. + if (email.hasFiles()) { + for (var key in post_data) { + request.write(post_data[key]); + } + } else { + request.write(post_data); } + request.end(); } |