aheckmann / node-ses

An Amazon SES api for nodejs with proper error handling.
http://aheckmann.github.com/node-ses
MIT License
200 stars 37 forks source link

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

Closed rickwaugh1 closed 9 years ago

rickwaugh1 commented 9 years ago

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."

markstos commented 9 years ago

It looks like our module is expecting XML to be returned and in this case perhaps something else is being returned, resulting in the "Parse Error".

We can look at handling this case better.

For your specific debugging, try reviewing the AWS SES API and doing a direct POST of the XML they are requesting and reviewing the output they returning to see what the issue might be.

http://aws.amazon.com/documentation/ses/

You could also try a competing package, like https://www.npmjs.com/package/aws-ses-mail

rickwaugh1 commented 9 years ago

Complete red herring. I had added the endpoint as a member on our aws config file, which also got sent when setting up the aws sdk - that cause the aws sdk to blow up when creating a connection to dynamodb. Taking it out of there and putting it into a separate file solved the issue.

markstos commented 9 years ago

Thanks for the feedback.

markstos commented 9 years ago

Since the issue didn't originate in our module or with Amazon, I'm going to close this issue for now, but would still welcome improvements to handling unexpected responses from Amazon.