summaryrefslogtreecommitdiffstats
path: root/lib/sendgrid.js
diff options
context:
space:
mode:
authorDavid Tomberlin <siyegen@gmail.com>2012-01-13 16:40:56 -0800
committerDavid Tomberlin <siyegen@gmail.com>2012-01-13 16:40:56 -0800
commit217ed28a36b2e156b74d705fc017efe88e1696ab (patch)
treef1743ad4b94050fb1bc0fcbcaf95bd127c58fc01 /lib/sendgrid.js
parenta3a7b743b2b6cde14498561fe1d637243f7cb75c (diff)
parent2fd759fa8136ce0123070a948fdb38255d9d7695 (diff)
downloadsendgrid-nodejs-217ed28a36b2e156b74d705fc017efe88e1696ab.zip
sendgrid-nodejs-217ed28a36b2e156b74d705fc017efe88e1696ab.tar.gz
sendgrid-nodejs-217ed28a36b2e156b74d705fc017efe88e1696ab.tar.bz2
Merge pull request #16 from partkyle/fix-sending
Fix Posting of non-multipart data
Diffstat (limited to 'lib/sendgrid.js')
-rw-r--r--lib/sendgrid.js14
1 files changed, 11 insertions, 3 deletions
diff --git a/lib/sendgrid.js b/lib/sendgrid.js
index 6ce98ec..0a8a0a9 100644
--- a/lib/sendgrid.js
+++ b/lib/sendgrid.js
@@ -42,8 +42,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, boundary);
var length = 0;
@@ -74,9 +75,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();
}