From b051ea7747e9df5345fccc31dad1395c8bb6c4a5 Mon Sep 17 00:00:00 2001 From: Guilherme Souza Date: Tue, 21 Jul 2015 06:49:15 -0300 Subject: [PATCH 1/6] added aws-region support --- README.md | 2 +- main.js | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index ad5d8aa..446df29 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ Verify the source email address with Amazon.
   var AmazonSES = require('amazon-ses');
-  var ses = new AmazonSES('access-key-id', 'secret-access-key');
+  var ses = new AmazonSES('access-key-id', 'secret-access-key', 'region');
   ses.verifyEmailAddress('foo@mailinator.com');
 
diff --git a/main.js b/main.js index 33fab32..6ae7866 100644 --- a/main.js +++ b/main.js @@ -6,9 +6,10 @@ var xml = require('xml2js'); var AmazonSES = (function() { - var init = function(key, secret) { + var init = function(key, secret, region) { this.accessKeyId = key; this.secretAccessKey = secret; + this.region = region; }; var hmac = function(key, str) { @@ -53,7 +54,8 @@ var AmazonSES = (function() { }; var call = function(opts) { - var host = 'email.us-east-1.amazonaws.com'; + + var host = 'email.'+this.region+'.amazonaws.com'; var path = '/'; var now = (new Date()).toUTCString(); @@ -94,8 +96,8 @@ var AmazonSES = (function() { }); }; - var Constructor = function(accessKeyId, secretAccessKey) { - init(accessKeyId, secretAccessKey); + var Constructor = function(accessKeyId, secretAccessKey, region) { + init(accessKeyId, secretAccessKey, region); }; Constructor.prototype = { From 8622ea8bcbc445634a92a740cecd4ac12b063a48 Mon Sep 17 00:00:00 2001 From: Antoine Rousseau Date: Wed, 24 Feb 2016 19:56:07 -0600 Subject: [PATCH 2/6] fail-safe XML parsing of response & updated dependencies --- .gitignore | 1 + main.js | 20 ++++++++++++-------- package.json | 19 +++++++++++++------ 3 files changed, 26 insertions(+), 14 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c2658d7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules/ diff --git a/main.js b/main.js index 6ae7866..93eafad 100644 --- a/main.js +++ b/main.js @@ -53,6 +53,8 @@ var AmazonSES = (function() { return params; }; + var parser = new xml.Parser({explicitArray : false}); + var call = function(opts) { var host = 'email.'+this.region+'.amazonaws.com'; @@ -83,16 +85,18 @@ var AmazonSES = (function() { }; request(options, function(error, response, body) { - var parser = new xml.Parser(); - parser.addListener('end', function(data) { - var err = null; - if (data.hasOwnProperty('Error')) { - err = new Error(data.Error.Message); + if (error) { + return opts.callback(error); + } + parser.parseString(body, function(error, data) { + if (error) { + return opts.callback(error); } - opts.callback(err, data); - + if (data.ErrorResponse) { + return opts.callback(new Error(data.ErrorResponse.Error.Message)); + } + opts.callback(null, data.SendEmailResponse.SendEmailResult); }); - parser.parseString(body); }); }; diff --git a/package.json b/package.json index 2edf0b0..9551a83 100644 --- a/package.json +++ b/package.json @@ -1,15 +1,22 @@ { "name": "amazon-ses", "description": "Simple Amazon SES Mailer", - "version": "0.0.3", + "version": "0.0.4", "author": "Jim Jenkins ", "dependencies": { - "request": "2.1.1", - "underscore": "1.2.1", - "xml2js": "0.1.11" + "request": "^2.69.0", + "underscore": "^1.8.3", + "xml2js": "^0.4.16" }, - "keywords": ["email", "amazon", "ses"], + "keywords": [ + "email", + "amazon", + "ses" + ], + "license": "MIT", "repository": "git://github.com/jjenkins/node-amazon-ses.git", "main": "main", - "engines": { "node": ">= 0.4.1" } + "engines": { + "node": ">= 0.4.1" + } } From de87970ad69986ec4409523c441cc40da62d5ce6 Mon Sep 17 00:00:00 2001 From: Antoine Rousseau Date: Wed, 24 Feb 2016 23:27:49 -0600 Subject: [PATCH 3/6] no need for explicitRoot in XML parser --- main.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/main.js b/main.js index 93eafad..b4ac7fe 100644 --- a/main.js +++ b/main.js @@ -53,7 +53,7 @@ var AmazonSES = (function() { return params; }; - var parser = new xml.Parser({explicitArray : false}); + var parser = new xml.Parser({explicitArray: false, explicitRoot: false}); var call = function(opts) { @@ -92,10 +92,10 @@ var AmazonSES = (function() { if (error) { return opts.callback(error); } - if (data.ErrorResponse) { - return opts.callback(new Error(data.ErrorResponse.Error.Message)); + if (data.Error) { + return opts.callback(new Error(data.Error.Message)); } - opts.callback(null, data.SendEmailResponse.SendEmailResult); + opts.callback(null, data); }); }); }; From 5cdc5d388f195fcb316b54be2f980bb3dff704b3 Mon Sep 17 00:00:00 2001 From: Antoine Rousseau Date: Wed, 24 Feb 2016 23:35:55 -0600 Subject: [PATCH 4/6] Update README.md --- README.md | 98 +++++++++++++++++++++++++------------------------------ 1 file changed, 45 insertions(+), 53 deletions(-) diff --git a/README.md b/README.md index 446df29..87f5b14 100644 --- a/README.md +++ b/README.md @@ -2,80 +2,72 @@ A simple Amazon SES wrapper, supports the following actions: -* DeleteVerifiedEmailAddress -* GetSendQuota -* GetSendStatistics -* ListVerifiedEmailAddresses -* SendEmail -* VerifyEmailAddress +* `DeleteVerifiedEmailAddress` +* `GetSendQuota` +* `GetSendStatistics` +* `ListVerifiedEmailAddresses` +* `SendEmail` +* `VerifyEmailAddress` -Does not currently support SendRawEmail. +Does not currently support `SendRawEmail`. ## Install -
-  npm install amazon-ses
-
- -Or from source: - -
-  git clone git://github.com/jjenkins/node-amazon-ses.git
-  cd amazon-ses
-  npm link .
-
+``` +npm install amazon-ses-with-region +``` ## Verify Source Email Verify the source email address with Amazon. -
-  var AmazonSES = require('amazon-ses');
-  var ses = new AmazonSES('access-key-id', 'secret-access-key', 'region');
-  ses.verifyEmailAddress('foo@mailinator.com');
-
+```js +var AmazonSES = require('amazon-ses-with-region'); +var ses = new AmazonSES('access-key-id', 'secret-access-key', 'region'); +ses.verifyEmailAddress('foo@mailinator.com'); +``` You will receive a confirmation email - click the link in that email to finish the verification process. ## Send Email -
-  ses.send({
-      from: 'foo@mailinator.com'
-    , to: ['bar@mailinator.com', 'jim@mailinator.com']
-    , replyTo: ['john@mailinator.com']
-    , subject: 'Test subject'
-    , body: {
-          text: 'This is the text of the message.'
-        , html: 'This is the html body of the message.'
-    }
-  });
-
+```js +ses.send({ + from: 'Foo ' + , to: ['bar@mailinator.com', 'jim@mailinator.com'] + , replyTo: ['john@mailinator.com'] + , subject: 'Test subject' + , body: { + text: 'This is the text of the message.' + , html: 'This is the html body of the message.' + } +}); +``` ## Get verified email addresses -
-  ses.listVerifiedEmailAddresses(function(result) {
-    console.log(result);
-  });
-
+```js +ses.listVerifiedEmailAddresses(function(result) { + console.log(result); +}); +``` ## Deleted a verified email address -
-  ses.deleteVerifiedEmailAddress('foo@mailinator.com', function(result) {
-    console.log(result);
-  });
-
+```js +ses.deleteVerifiedEmailAddress('foo@mailinator.com', function(result) { + console.log(result); +}); +``` ## Get Quota and Stats -
-  ses.getSendQuota(function(result) {
-    console.log(result);
-  });
+```js
+ses.getSendQuota(function(result) {
+  console.log(result);
+});
 
-  ses.getSendStatistics(function(result) {
-    console.log(result);
-  });
-
+ses.getSendStatistics(function(result) { + console.log(result); +}); +``` From 25e44b26da25341840eb26710adb2c586a8fce34 Mon Sep 17 00:00:00 2001 From: Antoine Rousseau Date: Fri, 26 Feb 2016 14:19:03 -0600 Subject: [PATCH 5/6] message body can be either text or html, or both --- main.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/main.js b/main.js index b4ac7fe..d90b859 100644 --- a/main.js +++ b/main.js @@ -39,12 +39,16 @@ var AmazonSES = (function() { var params = { 'Action': 'SendEmail' , 'Source': opts.from - , 'Message.Body.Text.Data': opts.body.text - , 'Message.Body.Text.Charset': 'UTF-8' - , 'Message.Body.Html.Data': opts.body.html - , 'Message.Body.Html.Charset': 'UTF-8' , 'Message.Subject.Data' : opts.subject }; + if (opts.body.text) { + params['Message.Body.Text.Data'] = opts.body.text; + params['Message.Body.Text.Charset'] = 'UTF-8'; + } + if (opts.body.html) { + params['Message.Body.Html.Data'] = opts.body.html; + params['Message.Body.Html.Charset'] = 'UTF-8'; + } _.extend(params, getDestinationList(opts.to, 'To')); _.extend(params, getDestinationList(opts.cc, 'Cc')); _.extend(params, getDestinationList(opts.bcc, 'Bcc')); From 33119a32188137d9cfd8b4d94ca2b0a114bdcd93 Mon Sep 17 00:00:00 2001 From: Antoine Rousseau Date: Wed, 2 Mar 2016 13:43:46 -0600 Subject: [PATCH 6/6] update package.json --- package.json | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 9551a83..4528805 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,13 @@ { "name": "amazon-ses", "description": "Simple Amazon SES Mailer", - "version": "0.0.4", + "version": "0.1.0", "author": "Jim Jenkins ", + "contributors": [ + "Antoine Rousseau " + ], + "homepage": "https://github.com/antoinerousseau/node-amazon-ses", + "bugs": "https://github.com/antoinerousseau/node-amazon-ses/issues", "dependencies": { "request": "^2.69.0", "underscore": "^1.8.3", @@ -14,7 +19,7 @@ "ses" ], "license": "MIT", - "repository": "git://github.com/jjenkins/node-amazon-ses.git", + "repository": "https://github.com/antoinerousseau/node-amazon-ses.git", "main": "main", "engines": { "node": ">= 0.4.1"