Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
98 changes: 45 additions & 53 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

<pre>
npm install amazon-ses
</pre>

Or from source:

<pre>
git clone git://github.com/jjenkins/node-amazon-ses.git
cd amazon-ses
npm link .
</pre>
```
npm install amazon-ses-with-region
```

## Verify Source Email

Verify the source email address with Amazon.

<pre>
var AmazonSES = require('amazon-ses');
var ses = new AmazonSES('access-key-id', 'secret-access-key');
ses.verifyEmailAddress('foo@mailinator.com');
</pre>
```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

<pre>
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 <b>html</b> body of the message.'
}
});
</pre>
```js
ses.send({
from: 'Foo <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 <b>html</b> body of the message.'
}
});
```

## Get verified email addresses

<pre>
ses.listVerifiedEmailAddresses(function(result) {
console.log(result);
});
</pre>
```js
ses.listVerifiedEmailAddresses(function(result) {
console.log(result);
});
```

## Deleted a verified email address

<pre>
ses.deleteVerifiedEmailAddress('foo@mailinator.com', function(result) {
console.log(result);
});
</pre>
```js
ses.deleteVerifiedEmailAddress('foo@mailinator.com', function(result) {
console.log(result);
});
```

## Get Quota and Stats

<pre>
ses.getSendQuota(function(result) {
console.log(result);
});
```js
ses.getSendQuota(function(result) {
console.log(result);
});

ses.getSendStatistics(function(result) {
console.log(result);
});
</pre>
ses.getSendStatistics(function(result) {
console.log(result);
});
```
42 changes: 26 additions & 16 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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'));
Expand All @@ -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();
Expand Down Expand Up @@ -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 = {
Expand Down
26 changes: 19 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
{
"name": "amazon-ses",
"description": "Simple Amazon SES Mailer",
"version": "0.0.3",
"version": "0.1.0",
"author": "Jim Jenkins <jim.jenkins@gmail.com>",
"contributors": [
"Antoine Rousseau <antoine@rousseau.im>"
],
"homepage": "https://github.com/antoinerousseau/node-amazon-ses",
"bugs": "https://github.com/antoinerousseau/node-amazon-ses/issues",
"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"],
"repository": "git://github.com/jjenkins/node-amazon-ses.git",
"keywords": [
"email",
"amazon",
"ses"
],
"license": "MIT",
"repository": "https://github.com/antoinerousseau/node-amazon-ses.git",
"main": "main",
"engines": { "node": ">= 0.4.1" }
"engines": {
"node": ">= 0.4.1"
}
}