GithubHelp home page GithubHelp logo

aheckmann / node-ses Goto Github PK

View Code? Open in Web Editor NEW
200.0 8.0 37.0 307 KB

An Amazon SES api for nodejs with proper error handling.

Home Page: http://aheckmann.github.com/node-ses

License: MIT License

JavaScript 100.00%

node-ses's Introduction

node-ses

==========

A simple and reliable Node.js mail for sending mail through Amazon SES.

Benefits

  • Does only one thing and does it well. Only the SendEmail and SendRawEmail API methods are implemented.
  • Good error handling:
    • Only "2xx" and "3xx" responses from Amazon are considered successful.
    • Returned error objects are the Error elements of Amazon's error responses with Type, Code, Message etc.
    • Support for the debug module is included if debugging is needed.
  • Tested and reliable. Includes test suite. Sending email to SES since 2012.

Synopsis

Start by creating a client object, and then call either the sendEmail or sendRawEmail method depending on your needs.

var ses = require('node-ses')
  , client = ses.createClient({key: 'key', secret: 'secret'});

// Give SES the details and let it construct the message for you.
client.sendEmail({
   to: '[email protected]'
 , from: '[email protected]'
 , cc: '[email protected]'
 , bcc: ['[email protected]', '[email protected]']
 , subject: 'greetings'
 , message: 'your <b>message</b> goes here'
 , altText: 'plain text'
}, function (err, data, res) {
 // ...
});

// ... or build a message from scratch yourself and send it.
client.sendRawEmail({
 , from: '[email protected]'
 , rawMessage: rawMessage
}, function (err, data, res) {
 // ...
});

Installation

npm install node-ses

The module has one primary export:

createClient()

You'll probably only be using this method. It takes an options object with the following properties:

`key` -  your AWS SES key. Defaults to checking `process.env.AWS_ACCESS_KEY_ID` and `process.env.AWS_ACCESS_KEY`
`secret` - your AWS SES secret. Defaults to `process.env.AWS_SECRET_ACCESS_KEY` and `process.env.AWS_SECRET_KEY`
`amazon` - [optional] the amazon end-point uri. defaults to `https://email.us-east-1.amazonaws.com`

Not all AWS regions support SES. Check SES region support to be sure the region you are in is supported.

var ses = require('node-ses')
  , client = ses.createClient({ key: 'key', secret: 'secret' });

client.sendEmail(options, function (err, data, res))

Composes an email message based on input data, and then immediately queues the message for sending.

There are several important points to know about SendEmail:

  • You can only send email from verified email addresses and domains; otherwise, you will get an "Email address not verified" error. If your account is still in the Amazon SES sandbox, you must also verify every recipient email address except for the recipients provided by the Amazon SES mailbox simulator. For more information, go to the Amazon SES Developer Guide.
  • The total size of the message cannot exceed 10 MB. This includes any attachments that are part of the message.
  • Amazon SES has a limit on the total number of recipients per message. The combined number of To:, CC: and BCC: email addresses cannot exceed 50. If you need to send an email message to a larger audience, you can divide your recipient list into groups of 50 or fewer, and then call Amazon SES repeatedly to send the message to each group.
  • For every message that you send, the total number of recipients (To:, CC: and BCC:) is counted against your sending quota - the maximum number of emails you can send in a 24-hour period. For information about your sending quota, go to the Amazon SES Developer Guide.

sendEmail receives an options object with the following properties:

`from` - email address from which to send (required)
`subject` - string (required). Must be encoded as UTF-8
`message` - can be html (required). Must be encoded as UTF-8.
`altText` - plain text version of message. Must be encoded as UTF-8.
`to` - email address or array of addresses
`cc` - email address or array of addresses
`bcc` - email address or array of addresses
`replyTo` - email address
`configurationSet` - SES configuration set name
`messageTags` - SES message tags: array of name/value objects, e.g. { name: xid, value: 1 }

At least one of to, cc or bcc is required.

Optional properties (overrides the values set in createClient):

`key` - AWS key
`secret` - AWS secret
`amazon` - AWS end point. Defaults to `https://email.us-east-1.amazonaws.com`

If you want to add a different end point than us-east-1, you can find a list here. (Note: Don't forget to add https://) The sendEmail method transports your message to the AWS SES service. If AWS returns an HTTP status code that's less than 200 or greater than or equal to 400, we will callback with an err object that is a direct tranalation of the Error element of the AWS error response.

See Error Handling section below for details on the structure of returned errors.

Check for errors returned since a 400 status is not uncommon.

The data returned in the callback is an object containing the parsed AWS response.

See the SES API Response docs for details.

The res returned by the callback represents the HTTP response to calling the SES REST API as the request module returns it.

The sendEmail method also be provided in all lowercase as sendemail for backwards compatibility.

client.sendRawEmail(options, function (err, data, res))

Sends an email message, with header and content specified by the client. The SendRawEmail action is useful for sending multipart MIME emails. The raw text of the message must comply with Internet email standards; otherwise, the message cannot be sent.

There are several important points to know about SendRawEmail:

  • You can only send email from verified email addresses and domains; otherwise, you will get an "Email address not verified" error. If your account is still in the Amazon SES sandbox, you must also verify every recipient email address except for the recipients provided by the Amazon SES mailbox simulator. For more information, go to the Amazon SES Developer Guide.
  • The total size of the message cannot exceed 10 MB. This includes any attachments that are part of the message.
  • Amazon SES has a limit on the total number of recipients per message. The combined number of To:, CC: and BCC: email addresses cannot exceed 50. If you need to send an email message to a larger audience, you can divide your recipient list into groups of 50 or fewer, and then call Amazon SES repeatedly to send the message to each group.
  • The To:, CC:, and BCC: headers in the raw message can contain a group list. Note that each recipient in a group list counts towards the 50-recipient limit. For every message that you send, the total number of recipients (To:, CC: and BCC:) is counted against your sending quota - the maximum number of emails you can send in a 24-hour period. For information about your sending quota, go to the Amazon SES Developer Guide.

sendRawEmail receives an options object with the following properties:

`from` - email address from which to send (required)
`rawMessage` - the raw text of the message which includes a header and a body (required)

Within the raw text of the message, the following must be observed:

  • The rawMessage value must contain a header and a body, separated by a blank line.
  • All required header fields must be present.
  • Each part of a multipart MIME message must be formatted properly.
  • MIME content types must be among those supported by AWS SES. For more information, see the SES Developer Guide.
  • The rawMessage content must be base64-encoded, if MIME requires it.

The sendRawEmail method transports your message to the AWS SES service. If Amazon returns an HTTP status code that's less than 200 or greater than or equal to 400, we will callback with an err object that is a direct translation of the Error element of aws error response.

See Error Handling section below for details on the structure of returned errors.

Example

var CRLF = '\r\n'
  , ses = require('node-ses')
  , client = ses.createClient({ key: 'key', secret: 'secret' })
  , rawMessage = [
    'From: "Someone" <[email protected]>',
    'To: "Someone Else" <[email protected]>',
    'Subject: greetings',
    'Content-Type: multipart/mixed;',
    '    boundary="_003_97DCB304C5294779BEBCFC8357FCC4D2"',
    'MIME-Version: 1.0',
    '',
    '--_003_97DCB304C5294779BEBCFC8357FCC4D2',
    'Content-Type: text/plain; charset="us-ascii"',
    'Content-Transfer-Encoding: quoted-printable',
    'Hi brozeph,',
    '',
    'I have attached a code file for you.',
    '',
    'Cheers.',
    '',
    '--_003_97DCB304C5294779BEBCFC8357FCC4D2',
    'Content-Type: text/plain; name="code.txt"',
    'Content-Description: code.txt',
    'Content-Disposition: attachment; filename="code.txt"; size=4;',
    '    creation-date="Mon, 03 Aug 2015 11:39:39 GMT";',
    '    modification-date="Mon, 03 Aug 2015 11:39:39 GMT"',
    'Content-Transfer-Encoding: base64',
    '',
    'ZWNobyBoZWxsbyB3b3JsZAo=',
    '',
    '--_003_97DCB304C5294779BEBCFC8357FCC4D2',
    ''
  ].join(CRLF);

client.sendRawEmail({
 , from: '[email protected]'
 , rawMessage: rawMessage
}, function (err, data, res) {
 // ...
});

Check for errors returned since a 400 status is not uncommon.

The data returned in the callback is an object containing the parsed Amazon json response.

See the SES API Response docs for details.

The res returned by the callback represents the HTTP response to calling the SES REST API as the request module returns it.

Error Handling

The errors returned when sending failed are JavaScript objects that correspond to the Error element as seen in Structure of an Error Response from the official documentation. The properties in error object we return include:

  • A Type element that identifies whether the error was a Receiver, Sender, or NodeSesInternal error
  • A Code element that identifies the type of error that occurred
  • A Message element that describes the error condition in a human-readable form
  • A Detail element that might give additional details about the error or might be empty

An error of Type NodeSesInternal is returned in three cases:

  • If the HTTP request to AWS fails so that we don't get a normal response from AWS. The Code will be RequestError and the Message will contain the HTTP request error.
  • If aws error response has invalid schema (Error element is missing), then the Code will be set to XmlError and the Message will contain explanation and the original response.

Example error response:

{
  "Type": "Sender",
  "Code": "ValidationError",
  "Message": "Value null at 'message.subject' failed to satisfy constraint: Member must not be null"
}

Debugging

# Enable in the shell
DEBUG="node-ses" ./server.js
// ... or temporarily set in your code before `node-ses` is required.
process.env.DEBUG='node-ses';

When debugging, it's useful to inspect the raw HTTP request and response send to Amazon. These can then checked against Amazon's documentation for the SendMail API method and the common errors that Amazon might return.

To turn on debugging printed to STDERR, set DEBUG=node-ses in the environment before running your script. You can also set process.env.DEBUG='node-ses'; in your code, before the node-ses module is required.

See the debug module docs for more debug output possibilities.

Running the Tests

Unit tests

npm test

To run the full tests, including actually using the AWS SES REST APIs with your credentials, set the following environment variables:

# Your SES Key and secret
NODE_SES_KEY
NODE_SES_SECRET

# An email that is both an verified sende that can also receive test emails. Possibly your own email address
NODE_SES_EMAIL

See Also

  • node-ses-any-promise is a fork with a promise-based API.
  • nodemailer has more features, including attachment support. There are many "transport" plugins available for it, including one for SES.

License

MIT

node-ses's People

Contributors

aheckmann avatar altayakkus avatar anandchowdhary avatar brozeph avatar bryant1410 avatar cellule avatar cromestant avatar dependabot[bot] avatar epegzz avatar henhan avatar jamonkko avatar jessetane avatar markstos avatar robludwig avatar snafkin547 avatar tamlyn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-ses's Issues

Signature error coming back from Amazon

Trying to send a simple email. Double checked the SES key and secret are correct...but I keep getting this:

"The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details."

I've used the credentials successfully via the SMTP method and the email was delivered. But I am trying to switch to the API based way but wasn't able to get past this error. Any pointers on where I can start looking?

Default permissions on AWS vs Region

Hi,

I've noticed that when creating SMTP credentials in SES I get a default smtp user which I use for a key and secret. By default this user gets the policy to send emails, but ONLY RAW:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "ses:SendRawEmail",
"Resource": ""
}
]
}
It doesn't contain the required:
{
"Effect": "Allow",
"Action": "ses:SendEmail",
"Resource": "
"
}
in the "Statement" array for using this method in node-ses.

Then on the side - I also get and error: "{"Type":"Sender","Code":"MessageRejected","Message":"Email address is not verified."}", but it is, and so is the domain, and my account is not in sandbox. I eventually figured out that this error is actually because I didn't specify the domain (defaults to us-west-1 -as stated-, but I need eu-west-1). After this i figured out the above. Not sure if this is straight amazon message or node-ses, but might be worth adding this to your ReadMe.MD as a possible reason to get this error, as I did run in circles for about an hour or 2...

SIGv4 signed requests using header will start to fail progressively after 10/29

AWS SES will stop accepting SIGv4 signed requests via the header starting on Oct. 29, 2020.

Any update to support this AWS SES change?

Full Message from AWS:

SES is working on an infrastructure upgrade with improved security controls. As part of this improvement, we monitored SIGv4 requests and determined that our Simple Email Service endpoints are currently receiving SIGv4 requests using the connection header from your AWS account. Please note that SIGv4 signed requests using this header will start to fail progressively after 10/29 and you will be required to remove this header from signed headers. Please refer to the documentation [1] [2] and reach out to AWS support [3] if you have any further questions or concerns.

[1] https://docs.aws.amazon.com/ses/latest/DeveloperGuide/using-ses-api-authentication.html
[2] https://docs.aws.amazon.com/general/latest/gr/sigv4-create-canonical-request.html
[3] https://aws.amazon.com/support

Discussion: retry when requests are throttled

@aheckmann Any objection to re-trying requests when they fail to due to AWS throttling them?

There are some downsides:

  • Memory growth due to email queued waiting for retry. This could be potentially be a lot. We either need to be OK with that, or have a maximum queue size to prevent exhausting memory.
  • Potentially calling back much later when a response.

I could also argue that throttling code belongs in an external module, but it's also appealing to have this handled in the single module that all my mail sending gets routed through.

For comparison, I checked was the AWS JS SDK does. It doesn't support throttling, I presume because the module is trying to closely mirror the HTTP REST API, which doens't help with throttling / retries, either.

Issue with Image which is send Via Mail in iOs default mail app & outlook

I am trying to send Email from node.js API using "node-ses". I attached image url code inside mail body.
inside my template i have also included.

<img src="' + host + '/images/ic_comscope.png" height="40">
It works completely inside Gmail & browser, But having issue in iOs default mail app & outlook.

note: i don't want suggestion related to attachments

Also base64 not works with "src" of "image" tag

Give any solution

SignatureDoesNotMatch

I have set my config as below.

var ses = require('node-ses')
let client = ses.createClient({ key: '<my key>', secret: '<my secret>',amazon: 'https://email.ap-south-1.amazonaws.com' });
console.log(client)
// Give SES the details and let it construct the message for you.
client.sendEmail({
   to: '[email protected]'
 , from: 'My verified domain address email'
 , subject: 'greetings'
 , message: 'your <b>message</b> goes here'
 , altText: 'plain text'
}, function (err, data, res) {
 // ...
 if(err){
  console.log(err)
  console.log('err occured.')
 }
 else{
  console.log(data)
  console.log('mail sent..check your inbox..')
 }
});

I am getting the below error.

{
  Type: 'Sender',
  Code: 'SignatureDoesNotMatch',
  Message: 'The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.'
}

The same config is working in aws-sdk. But I am getting this error in node-ses. Can anyone help me to figure out the problem in my setting?

How to use my html template?

I want to use my html template (let say index.html) to send as a message without pasting whole html content to message (sendemailoptions param) as a string.

Signature Version 4 requests that include a signed \'connection\' header

Hi all,

We are getting this issue, this appeared after AWS upgrade on March 30th.

Locally we were able to fix it comment the following lines:

node-ses/lib/email.js

line 206: //headers['Connection'] = 'Keep-Alive';
line 212: // , headers: headers

If you are able to push this fix we really appreciate it.

Thanks!

One of your two methods doesn't exist

There is no sendEmail function. Really hope I'm missing something!

Verified on linux and osx

Version 1.0.2

$ node
> var ses = require('node-ses');
undefined
> var client = ses.createClient({ key: 'a', secret: 'b' });
undefined
> client.sendEmail();
TypeError: Object #<SESClient> has no method 'sendEmail'

End-point uri

This is don't working for me:
amazon - [optional] the amazon end-point uri. defaults to https://email.us-west-2.amazonaws.com;
While I don't set the end-point uri as https://email.us-west-2.amazonaws.com forcibly, I'm have a "Email adress is not verified" error (address is verified). But when I set it clearly, error was fixed.

SyntaxError: `https://email.us-east-1.amazonaws.com` node-ses/lib/ses.js:50

Got an error message on my server when trying to use the module. I assume its some encoding issue with the ` character, it works fine on my desktop. It seemed to function correctly when i changed the ` to the '

image

/home/ogdans3/git/haavard/node_modules/node-ses/lib/ses.js:50

Is the special quotation mark important? Do you know how I resolve the syntax error?

sendEmail() doesn't work with special character in message

This works fine

var message = 'Test message';
console.log(message);
client.sendEmail({
        to: '[email protected]'
        , from: '[email protected]'
        , subject: 'Simple test message '
        , message: message
        , altText: message
    }, function (err, data, res) {
       if(err){
            console.error(err);
        }else{
            console.log(data);
        }
    });

This throw error SignatureDoesNotMatch

var message = `badFunction() is not defined:: ReferenceError: badFunction is not defined
   at Object.<anonymous> (services\test.js:19:5)`;
console.log(message);

client.sendEmail({
        to: '[email protected]'
        , from: '[email protected]'
        , subject: 'Special char test message '
        , message: message
        , altText: message
    }, function (err, data, res) {
       if(err){
            console.error(err);
        }else{
            console.log(data);
        }
    });

Screenshot

image

Using within Lambda

How to pass credentials to node-ses createClient() so that it can send an email from within a Lmbda invocation?

Using the AWS_ACCESS_KEY_ID & AWS_SECRET_ACCESS_KEY from the environment variables automatically available inside the lambda doesn't work (not without also specifying session token, apparently)

InvalidClientTokenId

Hi,

We're using this package, which is a thin wrapper around node-ses. We started receiving the above mentioned AWS error when sending mails. I dually checked to see if node-ses was updated to handle v4 signing, which it is (thank you for your work on this package).

I also checked to see that the wrapper we're using was updated to use the correct version of node-ses, which it is.

Is anyone else receiving these errors? Is there anything we need to do, apart from be on the latest packages?

I'd appreciate any help.

Thanks!

Fail more gracefully when we can't parse the response returned by Amazon as XML

We have used this module successfully on a few projects, but are having problems now on a new project. I had not had to provide an endpoint before, but had to now, which is fine. Endpoint we are using is email-smtp.us-west-2.amazonaws.com. But when I do it so, and send, I get the following error:

{ [NetworkingError: Parse Error]
message: 'Parse Error',
bytesParsed: 0,
code: 'NetworkingError',
region: 'us-west-2',
hostname: 'email-smtp.us-west-2.amazonaws.com',
retryable: true,
time: Wed Dec 10 2014 09:18:38 GMT-0800 (PST) } null
NetworkingError: Parse Error
at CleartextStream.socketOnData (http.js:1583:20)
at CleartextStream.read as _read
at CleartextStream.Readable.read (_stream_readable.js:320:10)
at EncryptedStream.write as _write
at doWrite (_stream_writable.js:226:10)
at writeOrBuffer (_stream_writable.js:216:5)
at EncryptedStream.Writable.write (_stream_writable.js:183:11)
at write (_stream_readable.js:583:24)
at flow (_stream_readable.js:592:7)
at Socket.pipeOnReadable (_stream_readable.js:624:5)

Our code:

var SES = require("node-ses");
var EmailClient = SES.createClient(
{
key: aws_config["accessKeyId"],
secret: aws_config["secretAccessKey"],
amazon: aws_config["endpoint"]
});

EmailClient.sendemail(email, function(err, result)
{
if (err)
{
mainLog.log("error", "Failed to send email " + err.message );
}
next(err, result);
});

While troubleshooting, I also saw the following in the AWS console. We have always justed use AWS credentials, so I'm confused:

"To send email through Amazon SES using SMTP, you must create SMTP credentials. SMTP credentials are a username and password that you use when you connect to the Amazon SES SMTP endpoint. You can use the same set of SMTP credentials for all regions in which Amazon SES is available.

To obtain your SMTP credentials, click the button below. For more information about SMTP credentials, click here.

Create My SMTP Credentials
Note: Your SMTP user name and password are not the same as your AWS access key ID and secret access key. Do not attempt to use your AWS credentials to authenticate yourself against the SMTP endpoint. For more information about credential types, click here."

Error: Parse Error] bytesParsed: 0, code: 'HPE_INVALID_CONSTANT'

var ses = require('node-ses')
, client = ses.createClient({ key: 'key', secret: 'secret', amazon:'https://email-smtp.us-west-2.amazonaws.com' });

// Give SES the details and let it construct the message for you.
client.sendEmail({
to: '[email protected]'
, from: '[email protected]'
, sender: '[email protected]'
, bcc: ['[email protected]']
, subject: 'greetings'
, message: 'your goes here'
, altText: 'plain text'
}, function (err, data) {
if(err){
console.log ('err',err);
}
else{
console.log('data',data);
}
});

Signing broken in `v3.0.0`

Setting json: true in v3.0.0 brakes signing:

body:
   { Error:
      { Code: 'SignatureDoesNotMatch',
        Message:
         'The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.',
        Type: 'Sender' },
     RequestId: 'ce056628-f806-48a7-b7a5-f9b47c75d063' } }

Documentation for published version

I think it should be made clearer where the documentation for the version published to npm is or when breaking changes are made if you could update the published version that'd be great. Nice library by the way.

Serverless sls lambda error

I can send emails local dev but when I deploy Cloudwatch logs are:

RequestError NodeSesInternal Error: Client network socket disconnected before secure TLS connection was established
at connResetException (internal/errors.js:608:14)
at TLSSocket.onConnectEnd (_tls_wrap.js:1514:19)
at Object.onceWrapper (events.js:416:28)
at TLSSocket.emit (events.js:322:22)
at TLSSocket.EventEmitter.emit (domain.js:482:12)
at endReadableNT (_stream_readable.js:1187:12)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
code: 'ECONNRESET',
path: null,
host: 'email.ap-southeast-2.amazonaws.com',
port: 443,
localAddress: undefined

?, thanks!

Error handling

First, i dont know it is node-ses or ses level issue.

  1. If i try to send mail on [email protected] (domain exists but mail id does not),
    1st time it success, 2nd time it is giving error.
  2. if i try to send mail on [email protected] it always show me success!

Any clue?

Raxit

Does this conform with RFC 2822?

Hi,

We've stumbled on your code while looking to a solution where some emails we were sending using Amazon SES SendRawEmail were bouncing with error codes 500, 501 and a few others due to lines being too long. It appears that subjects that are longer than 76 characters need to be split into multiple line with everything after the 1st line starting with a space and all lines ending with a CRLF.

Similar issue with HTML emails where it seems all HTML is treated as one line and also needs to be split up with CRLF.

Does your package handle the issues with long lines in HTML emails and subjects?

The request signature we calculated does not match the signature you provided.

I'm sending an email using the following code:

client.sendemail({
    to: [ data.to.split( ',' ) ],
    from: data.from,
    subject: data.subject,
    message: data.html,
    altText: data.text
  }, function( err, data, res ) {
    console.log( 'sent with success -->', err, data, res );
    if ( err ) {
      callbacks.error();
    } else {
      callbacks.success();
    }
  });

and i'm getting the following output:

sent with success --> { Type: 'Sender',
  Code: 'SignatureDoesNotMatch',
  Message: 'The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.' } undefined undefined

My key and my secret are correct, is it possible to be an error on the module or I'm doing something wrong?

AWS SES having problems and the library fails at email.js line 230

Amazon had lots of problems today. It caused havoc with our system. When we tried to send an email it looks like amazon is handing you something you arent expecting (bad xml?) and it brings down my whole node process even though we are wrapping all of our stuff in bluebird promises. Here is my stack trace:

App 1488 stderr: events.js:141
App 1488 stderr: throw er; // Unhandled 'error' event
App 1488 stderr: ^
App 1488 stderr:
App 1488 stderr: TypeError: Cannot read property 'ErrorResponse' of null
App 1488 stderr: at /home/ec2-user/www/velocicast_prod/node_modules/node-ses/lib/email.js:230:31
App 1488 stderr: at Parser. (/home/ec2-user/www/velocicast_prod/node_modules/xml2js/lib/xml2js.js:489:18)
App 1488 stderr: at emitOne (events.js:77:13)
App 1488 stderr: at Parser.emit (events.js:169:7)
App 1488 stderr: at Parser.exports.Parser.Parser.parseString (/home/ec2-user/www/velocicast_prod/node_modules/xml2js/lib/xml2js.js:499:16)
App 1488 stderr: at Parser.parseString (/home/ec2-user/www/velocicast_prod/node_modules/xml2js/lib/xml2js.js:7:59)
App 1488 stderr: at Email._processResponse (/home/ec2-user/www/velocicast_prod/node_modules/node-ses/lib/email.js:219:22)
App 1488 stderr: at Request._callback (/home/ec2-user/www/velocicast_prod/node_modules/node-ses/lib/email.js:197:10)
App 1488 stderr: at Request.self.callback (/home/ec2-user/www/velocicast_prod/node_modules/request/request.js:186:22)
App 1488 stderr: at emitTwo (events.js:87:13)
App 1488 stderr: at Request.emit (events.js:172:7)
App 1488 stderr: at Request. (/home/ec2-user/www/velocicast_prod/node_modules/request/request.js:1081:10)
App 1488 stderr: at emitOne (events.js:77:13)
App 1488 stderr: at Request.emit (events.js:169:7)
App 1488 stderr: at IncomingMessage. (/home/ec2-user/www/velocicast_prod/node_modules/request/request.js:1001:12)
App 1488 stderr: at IncomingMessage.g (events.js:260:16)
App 1488 stderr: at emitNone (events.js:72:20)
App 1488 stderr: at IncomingMessage.emit (events.js:166:7)
App 1488 stderr: at endReadableNT (_stream_readable.js:921:12)
App 1488 stderr: at nextTickCallbackWith2Args (node.js:442:9)
App 1488 stderr: at process._tickDomainCallback (node.js:397:17)

Your code looks like you have good, responsible error handling in there for the most part. However, it looks like you need to test like this:

if(result && result.ErrorResponse){
return callback(result.ErrorResponse.Error)
}else{
return callback('unexpected response from SES');
}

HPE_INVALID_CONSTANT

I'm getting [Error: Parse Error] bytesParsed: 0, code: 'HPE_INVALID_CONSTANT' when I run this:

'use strict';
var ses = require('node-ses'),
    client = ses.createClient({ key: '*****', secret: '*****', amazon: 'https://email-smtp.us-east-1.amazonaws.com' });

client.sendemail({
    to: '[email protected]',
    from: '[email protected]',
    subject: 'Sending email through Node and Amazon SES Test',
    message: 'Did you get this?',
    altText: 'Did you get this?'
}, function (err, data, res) {
    console.log('res= ' + res);

    if (err) {
    console.log(err); 
    }

    console.log(data);
});

Any thoughts?

Invalid protocol error

This is probably something on my end, but I'm not really sure.

/var/app/current/node_modules/aws-sdk/lib/sequential_executor.js:228
throw err;
^
Error: Invalid protocol
at Request.init (/var/app/current/node_modules/node-ses/node_modules/request/main.js:274:31)
at new Request (/var/app/current/node_modules/node-ses/node_modules/request/main.js:102:8)
at request (/var/app/current/node_modules/node-ses/node_modules/request/main.js:800:11)
at post (/var/app/current/node_modules/node-ses/lib/ses.js:275:3)
at Email.send (/var/app/current/node_modules/node-ses/lib/ses.js:241:3)
at SESClient.sendemail (/var/app/current/node_modules/node-ses/lib/ses.js:59:9)

internal "RequestError" Message should return a string, not an object

When we catch non-Amazon-Web-Services errors, we try to present them in the format that AWS does for consistency.

AWS returns a human-readable string in the Message field. But here, when we capture a "RequestError", we are currently returning an object:

https://github.com/aheckmann/node-ses/blob/master/lib/email.js#L61

Here's an example of object that was actually returned:

{
  "code": "ECONNRESET",
  "errno": "ECONNRESET",
  "syscall": "read"
}

Unfortunately, no part of that is a human-readable description that we could directly map to our own Message property.

We could use the errno library to get human-readable descriptions of the errors, in cases where the errno key is found.

The current mismatch between strings and objects could cause a failure elsewhere in an application if it's expecting that "Message" will always be a string.

SendRawEmail

It would be great if this library could support the SendRawEmail API for sending multipart emails. (for embedding images)

credentials

What are the credentials that are to be given?
Either SES smtp crentials or the IAM credentials

Document end point usage

I know this is an Amazon thing, but I managed to lose some time over this. Never had to specify and endpoint when using your module before. Figured out how to specify the endpoint, but didn't include the protocol.

Something like, "Not all AWS regions support SES, so it's a good idea to check and specify which region to send to. Some regions require https. An example would be:

        var EmailClient = SES.createClient(
        {
            key:"ABCDEFGH",
            secret: "ABCDBEDF",
            amazon: "https://email.us-west-2.amazonaws.com"
        });

wish: automatic retry support

Would you be interested in a patch that adds support for automatically attempting to resend the message in case of an intermittent failure?

I have in mind using the retry module, and exposing a way for users to specify their own retry settings if they are interested.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.