From 22bcc359af9a1fb4c50738f76aeb72fddeb65fb8 Mon Sep 17 00:00:00 2001 From: Tushar Bhushan Date: Wed, 9 Sep 2015 12:19:38 -0700 Subject: [PATCH 01/16] changed the cc/bcc to use the web api; change potentially breaking --- lib/email.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/email.js b/lib/email.js index 5f6be7a63..3b2ad850f 100644 --- a/lib/email.js +++ b/lib/email.js @@ -59,12 +59,12 @@ Email.prototype.setHeaders = function(object_literal) { }; Email.prototype.addTo = function(to) { - this.smtpapi.addTo(to); + this.to.push(to); return this; }; Email.prototype.setTos = function(tos) { - this.smtpapi.setTos(tos); + this.to = tos; return this; }; From f114df54856ea44f19aae81490bf975da41227ed Mon Sep 17 00:00:00 2001 From: Tushar Bhushan Date: Wed, 9 Sep 2015 14:59:13 -0700 Subject: [PATCH 02/16] removed keys --- test.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 test.js diff --git a/test.js b/test.js new file mode 100644 index 000000000..b37261c36 --- /dev/null +++ b/test.js @@ -0,0 +1,15 @@ +var sg = require('./lib/sendgrid')("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"); + +var email = new sg.Email(); + +email.addTo('tushar@sendgr.com'); +email.subject = 'Testing CC + BCC'; +email.from = 'me@example.com'; +email.text = 'Testing'; +email.addCc('tushar@sendgrid.com'); +email.bcc = 'tushar@sendgrid.com'; + +sg.send(email, function(err, json) { + if (err) console.error(err); + console.log(json); +}); From ea62e51d8c2b41df16d0ec8ef4f474457da0d671 Mon Sep 17 00:00:00 2001 From: Tushar Bhushan Date: Wed, 9 Sep 2015 15:10:51 -0700 Subject: [PATCH 03/16] wrong repo --- test.js | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 test.js diff --git a/test.js b/test.js deleted file mode 100644 index b37261c36..000000000 --- a/test.js +++ /dev/null @@ -1,15 +0,0 @@ -var sg = require('./lib/sendgrid')("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"); - -var email = new sg.Email(); - -email.addTo('tushar@sendgr.com'); -email.subject = 'Testing CC + BCC'; -email.from = 'me@example.com'; -email.text = 'Testing'; -email.addCc('tushar@sendgrid.com'); -email.bcc = 'tushar@sendgrid.com'; - -sg.send(email, function(err, json) { - if (err) console.error(err); - console.log(json); -}); From 39dad636294885d7d6b7eabe5fa5795b0d72dfe7 Mon Sep 17 00:00:00 2001 From: Tushar Bhushan Date: Wed, 9 Sep 2015 15:23:20 -0700 Subject: [PATCH 04/16] removed a test; removed the to param in smtp api hence test is no longer relevant --- test/lib/email.test.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/test/lib/email.test.js b/test/lib/email.test.js index 120a3dac6..a9ddd72ae 100644 --- a/test/lib/email.test.js +++ b/test/lib/email.test.js @@ -45,17 +45,17 @@ describe('Email', function () { expect(format.to).to.equal(payload.to); }); - it('should not have multiple TOs if as an array but also set on smtpapi via addTo', function() { - var payload = Object.create(default_payload); - payload.to = ['david.tomberlin@sendgrid.com', 'otherguy@sendgrid.com']; - var email = new Email(payload); - email.addTo(payload.to[0]); - email.addTo(payload.to[1]); + // it('should not have multiple TOs if as an array but also set on smtpapi via addTo', function() { + // var payload = Object.create(default_payload); + // payload.to = ['david.tomberlin@sendgrid.com', 'otherguy@sendgrid.com']; + // var email = new Email(payload); + // email.addTo(payload.to[0]); + // email.addTo(payload.to[1]); - var format = email.toWebFormat(); + // var format = email.toWebFormat(); - expect(format.to).to.equal(payload.from); - }); + // expect(format.to).to.equal(payload.from); + // }); it('should have multiple BCCs if as an array', function() { var payload = Object.create(default_payload); From c31b9aee1ecdf76e819a255ca633ff6d558f5dbc Mon Sep 17 00:00:00 2001 From: Tushar Bhushan Date: Wed, 7 Oct 2015 15:10:39 -0700 Subject: [PATCH 05/16] updated readme with changes --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index c9c7e447a..f5d2fe664 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,18 @@ This nodejs module allows you to quickly and easily send emails through SendGrid [![BuildStatus](https://travis-ci.org/sendgrid/sendgrid-nodejs.svg?branch=master)](https://travis-ci.org/sendgrid/sendgrid-nodejs) [![NPM version](https://badge.fury.io/js/sendgrid.svg)](http://badge.fury.io/js/sendgrid) +WARNING: This module was recently upgraded from [1.9.x](https://github.com/sendgrid/sendgrid-nodejs/tree/v1.9.1) to 2.X. There were API breaking changes for various method names. See [usage](https://github.com/sendgrid/sendgrid-nodejs#usage) for up to date method names. + +PLEASE READ THIS + +TLDR: If you upgrade and don't change your code appropriately, things WILL break. + +One of the most notable changes is how addTo() behaves. We are now using our Web API parameters instead of the X-SMTPAPI header. What this means is that if you call addTo() multiple times for an email, ONE email will be sent with each email address visible to everyone. To utilize the original behavior of having an individual personalized email sent to each recipient you must now use addSmtpapiTo(). This will break substitutions if there is more than one To address added unless you update to use addSmtpapiTo(). + +Smtpapi addressing methods cannot be mixed with non Smtpapi addressing methods. Meaning you cannot currently use Cc and Bcc with addSmtpapiTo(). + +The send() method now raises a \SendGrid\Exception by default if the response code is not 200 and returns an instance of \SendGrid\Response. + ```javascript var sendgrid = require('sendgrid')(sendgrid_api_key); sendgrid.send({ From 4eea56b1182c20bcf02508b76cea6875d438f301 Mon Sep 17 00:00:00 2001 From: Tushar Bhushan Date: Wed, 7 Oct 2015 15:10:54 -0700 Subject: [PATCH 06/16] added smtpapi add and set tos --- lib/email.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/email.js b/lib/email.js index 3b2ad850f..292043dec 100644 --- a/lib/email.js +++ b/lib/email.js @@ -63,6 +63,16 @@ Email.prototype.addTo = function(to) { return this; }; +Email.prototype.setSmtpapiTos = function(tos) { + this.smtpapi.setTos(tos); + return this; +}; + +Email.prototype.addSmtpapiTo = function(to) { + this.smtpapi.addTo(to); + return this; +}; + Email.prototype.setTos = function(tos) { this.to = tos; return this; From ce1e693d24c587047dfd775730245a62ead4b24d Mon Sep 17 00:00:00 2001 From: Tushar Bhushan Date: Wed, 7 Oct 2015 15:11:16 -0700 Subject: [PATCH 07/16] modified/added tests for smtpapi methods --- test/lib/email.test.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/test/lib/email.test.js b/test/lib/email.test.js index a9ddd72ae..835cc0452 100644 --- a/test/lib/email.test.js +++ b/test/lib/email.test.js @@ -119,13 +119,25 @@ describe('Email', function () { var payload = Object.create(default_payload); payload.to = ""; var email = new Email(payload); - email.addTo("test@test.com"); + email.addSmtpapiTo("test@test.com"); var format = email.toWebFormat(); - expect(JSON.parse(format['x-smtpapi']).to).to.not.be.empty; expect(format.to).to.not.be.empty; + expect(JSON.parse(format['x-smtpapi']).to).to.not.be.empty; }); + it('should have to addresses if there is no tos set but there are smtpapi tos set', function() { + var payload = Object.create(default_payload); + payload.to = ""; + var email = new Email(payload); + email.setSmtpapiTos(["test@test.com", "test2@test.com"]); + var format = email.toWebFormat(); + + expect(format.to).to.not.be.empty; + expect(JSON.parse(format['x-smtpapi']).to).to.not.be.empty; + expect(JSON.parse(format['x-smtpapi']).to).to.be.an.array; + }) + it("should set a fromname if one is provided", function() { var payload = Object.create(default_payload); var email = new Email({from: 'test@test.com', fromname:'Tester T. Testerson', subject: 'testing', text: 'testing'}); From 0843533b01d930f60af2e702033c4c5f6c66276c Mon Sep 17 00:00:00 2001 From: Tushar Bhushan Date: Wed, 7 Oct 2015 15:29:44 -0700 Subject: [PATCH 08/16] version bump --- CHANGELOG.md | 4 ++++ package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c88d54ff8..57b822b55 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Change Log All notable changes to this project will be documented in this file. +## [2.0.0] - +## Fixed +- Add cc now uses the WebAPI instead of the SMTPApi. Read disclaimer for details + ## [1.9.1] - 2015-7-20 ### Changed - Pinned request version to be less than `2.59.0` because it broke something diff --git a/package.json b/package.json index 915691529..36280926e 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ ], "name": "sendgrid", "description": "Official SendGrid NodeJS library.", - "version": "1.9.2", + "version": "2.0.0", "homepage": "http://sendgrid.com", "repository": { "type": "git", From 05910ebb6ed1670e4e5dea1cf74bda1594012cc6 Mon Sep 17 00:00:00 2001 From: Tushar Bhushan Date: Wed, 7 Oct 2015 15:35:22 -0700 Subject: [PATCH 09/16] version bump - test --- test/lib/sendgrid.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/lib/sendgrid.test.js b/test/lib/sendgrid.test.js index 9b5654ac3..ad293e0b8 100644 --- a/test/lib/sendgrid.test.js +++ b/test/lib/sendgrid.test.js @@ -12,7 +12,7 @@ var nock = require('nock'); describe('SendGrid', function () { it('version should be set', function() { var sendgrid = SendGrid(API_USER, API_KEY); - expect(sendgrid.version).to.equal("1.9.2"); + expect(sendgrid.version).to.equal("2.0.0"); }); it('should be an instance of SendGrid', function() { From dc2311503edb5fb5079ce889b50342c3ff168791 Mon Sep 17 00:00:00 2001 From: Tushar Bhushan Date: Wed, 7 Oct 2015 15:41:06 -0700 Subject: [PATCH 10/16] update travis to display correct link --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 608411bff..7fd22f1ec 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,6 +13,6 @@ notifications: template: - '%{repository} Build %{build_number} on branch %{branch} by %{author}: %{message} - View on GitHub' + View on GitHub' format: html notify: true From 9c80b8739b5bf7ce77d8f37e99d28eb34fe5301f Mon Sep 17 00:00:00 2001 From: Tushar Bhushan Date: Wed, 7 Oct 2015 15:41:06 -0700 Subject: [PATCH 11/16] update travis template --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 608411bff..740146161 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,6 +13,6 @@ notifications: template: - '%{repository} Build %{build_number} on branch %{branch} by %{author}: %{message} - View on GitHub' + View on GitHub' format: html notify: true From c260c6869acb5be71f08fd7385ba35f34a4b7ea5 Mon Sep 17 00:00:00 2001 From: Elmer Thomas Date: Wed, 7 Oct 2015 16:30:05 -0700 Subject: [PATCH 12/16] Update .travis.yml --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7fd22f1ec..7ebe36b7c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ node_js: - "0.12" - "iojs" before_install: -- npm install -g npm@next +- npm install -g npm@2 notifications: hipchat: rooms: From f340154925b5334d1643578ea6e0698f92072cda Mon Sep 17 00:00:00 2001 From: Tushar Bhushan Date: Wed, 7 Oct 2015 16:38:58 -0700 Subject: [PATCH 13/16] update travis template -- again --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7ebe36b7c..222372573 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,6 +13,6 @@ notifications: template: - '%{repository} Build %{build_number} on branch %{branch} by %{author}: %{message} - View on GitHub' + View on GitHub' format: html notify: true From 28d70fb91b4fc237b607796218bdbe857cf6da95 Mon Sep 17 00:00:00 2001 From: Tushar Bhushan Date: Thu, 8 Oct 2015 18:42:43 -0700 Subject: [PATCH 14/16] update readme --- README.md | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f5d2fe664..a3487c4c5 100644 --- a/README.md +++ b/README.md @@ -7,9 +7,9 @@ This nodejs module allows you to quickly and easily send emails through SendGrid WARNING: This module was recently upgraded from [1.9.x](https://github.com/sendgrid/sendgrid-nodejs/tree/v1.9.1) to 2.X. There were API breaking changes for various method names. See [usage](https://github.com/sendgrid/sendgrid-nodejs#usage) for up to date method names. -PLEASE READ THIS +## PLEASE READ THIS -TLDR: If you upgrade and don't change your code appropriately, things WILL break. +**TLDR: If you upgrade and don't change your code appropriately, things *WILL* break.** One of the most notable changes is how addTo() behaves. We are now using our Web API parameters instead of the X-SMTPAPI header. What this means is that if you call addTo() multiple times for an email, ONE email will be sent with each email address visible to everyone. To utilize the original behavior of having an individual personalized email sent to each recipient you must now use addSmtpapiTo(). This will break substitutions if there is more than one To address added unless you update to use addSmtpapiTo(). @@ -17,6 +17,8 @@ Smtpapi addressing methods cannot be mixed with non Smtpapi addressing methods. The send() method now raises a \SendGrid\Exception by default if the response code is not 200 and returns an instance of \SendGrid\Response. +## Sample + ```javascript var sendgrid = require('sendgrid')(sendgrid_api_key); sendgrid.send({ @@ -173,6 +175,8 @@ email.subject = "This is a subject"; You can add one or multiple TO addresses using `addTo`. +**Note**: One of the most notable changes is how `addTo()` behaves. We are now using our Web API parameters instead of the X-SMTPAPI header. What this means is that if you call `addTo()` multiple times for an email, **ONE** email will be sent with each email address visible to everyone. In oder to use the header, please call the `addSmtpapiTo()` method. + ```javascript var email = new sendgrid.Email(); email.addTo('foo@bar.com'); @@ -180,16 +184,33 @@ email.addTo('another@another.com'); sendgrid.send(email, function(err, json) { }); ``` -NOTE: This is different than setting an array on `to`. The array on `to` will show everyone the to addresses it was sent to. Using addTo will not. Usually, you'll want to use `addTo`. +#### addSmtpapiTo + + +```javascript +var email = new sendgrid.Email() +email.addSmtpapiTo('test@test.com'); +sendgrid.send(email, function(err, json) { }); +``` #### setTos +**Note**: The `setTos()` method now utilizes the Web API as opposed to using the X-SMTPAPI header. Please refer to the note posted on the top of this page. In order to use the header, you will need to use the `setSmtpapiTos()` method. + ```javascript var email = new sendgrid.Email(); email.setTos(['foo@bar.com', 'another@another.com']); sendgrid.send(email, function(err, json) { }); ``` +#### setSmtpapiTos + +```javascript +var email = new sendgrid.Email(); +email.setSmtpapiTos(["test@test.com","test2@test.com"]); +sendgrid.send(email, function(err, json) { }); +``` + #### setFrom ```javascript From 9e993f81fe99180406cb9a23f173535318c2a680 Mon Sep 17 00:00:00 2001 From: Tushar Bhushan Date: Thu, 8 Oct 2015 18:43:00 -0700 Subject: [PATCH 15/16] added tests for smtpapi methods --- test/lib/email.test.js | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/test/lib/email.test.js b/test/lib/email.test.js index 835cc0452..bf70334c6 100644 --- a/test/lib/email.test.js +++ b/test/lib/email.test.js @@ -136,7 +136,34 @@ describe('Email', function () { expect(format.to).to.not.be.empty; expect(JSON.parse(format['x-smtpapi']).to).to.not.be.empty; expect(JSON.parse(format['x-smtpapi']).to).to.be.an.array; - }) + }); + + it('should have a to address using addTo if there is no smtpapi to', function(){ + var payload = Object.create(default_payload); + payload.to = ""; + var email = new Email(payload); + email.addTo('test@test.com'); + email.addTo('test1@test.com'); + var format = email.toWebFormat(); + + expect(format.to).to.not.be.empty; + expect(format.to[0]).to.equal('test@test.com'); + expect(format.to[1]).to.equal('test1@test.com'); + }); + + it('should have a to addresses using setTos if there is no smtpapi to', function(){ + var payload = Object.create(default_payload); + payload.to = ""; + var email = new Email(payload); + email.setTos(['test@test.com', 'test1@test.com']); + + var format = email.toWebFormat(); + + expect(format.to).to.not.be.empty; + expect(format.to).to.be.an.array; + expect(format.to[0]).to.equal('test@test.com'); + expect(format.to[1]).to.equal('test1@test.com'); + }); it("should set a fromname if one is provided", function() { var payload = Object.create(default_payload); From 7b0688796ed0a7e04c696f7af9695f57fdca5bad Mon Sep 17 00:00:00 2001 From: Tushar Bhushan Date: Thu, 8 Oct 2015 18:44:49 -0700 Subject: [PATCH 16/16] removed extraneous tests --- test/lib/email.test.js | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/test/lib/email.test.js b/test/lib/email.test.js index bf70334c6..60f29f34e 100644 --- a/test/lib/email.test.js +++ b/test/lib/email.test.js @@ -45,18 +45,6 @@ describe('Email', function () { expect(format.to).to.equal(payload.to); }); - // it('should not have multiple TOs if as an array but also set on smtpapi via addTo', function() { - // var payload = Object.create(default_payload); - // payload.to = ['david.tomberlin@sendgrid.com', 'otherguy@sendgrid.com']; - // var email = new Email(payload); - // email.addTo(payload.to[0]); - // email.addTo(payload.to[1]); - - // var format = email.toWebFormat(); - - // expect(format.to).to.equal(payload.from); - // }); - it('should have multiple BCCs if as an array', function() { var payload = Object.create(default_payload); payload.bcc = ['david.tomberlin@sendgrid.com', 'otherguy@sendgrid.com'];