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/README.md b/README.md index ad5d8aa..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');
- 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
- 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);
+});
+```
diff --git a/main.js b/main.js
index 33fab32..d90b859 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) {
@@ -38,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'));
@@ -52,8 +57,11 @@ var AmazonSES = (function() {
return params;
};
+ var parser = new xml.Parser({explicitArray: false, explicitRoot: false});
+
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();
@@ -81,21 +89,23 @@ 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.Error) {
+ return opts.callback(new Error(data.Error.Message));
+ }
+ opts.callback(null, data);
});
- parser.parseString(body);
});
};
- var Constructor = function(accessKeyId, secretAccessKey) {
- init(accessKeyId, secretAccessKey);
+ var Constructor = function(accessKeyId, secretAccessKey, region) {
+ init(accessKeyId, secretAccessKey, region);
};
Constructor.prototype = {
diff --git a/package.json b/package.json
index 2edf0b0..4528805 100644
--- a/package.json
+++ b/package.json
@@ -1,15 +1,27 @@
{
"name": "amazon-ses",
"description": "Simple Amazon SES Mailer",
- "version": "0.0.3",
+ "version": "0.1.0",
"author": "Jim Jenkins