Reputation: 2494
I'm using "aws-sdk": "^2.117.0", my code looks like this:
var AWS = require('aws-sdk');
exports.sendAWSMail = function(message, destination){
const ses = new AWS.SES();
// http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SES.html#sendEmail-property
const sendEmail = ses.sendEmail;
var data = {
Destination: {
ToAddresses: [
"[email protected]"
]
},
Message: {
Body: {
Html: {
Charset: "UTF-8",
Data: "This message body contains HTML formatting. It can, for example, contain links like this one: <a class=\"ulink\" href=\"http://docs.aws.amazon.com/ses/latest/DeveloperGuide\" target=\"_blank\">Amazon SES Developer Guide</a>."
},
Text: {
Charset: "UTF-8",
Data: "This is the message body in text format."
}
},
Subject: {
Charset: "UTF-8",
Data: "Test email"
}
},
Source: "[email protected]",
}
sendEmail(data)
}
But I get this error:
TypeError: this.makeRequest is not a function at svc.(anonymous function) (/Users/iagowp/Desktop/trampos/frutacor/node_modules/aws-sdk/lib/service.js:499:23)
I didn't find any Node examples at their website, but from what I've seen elsewhere (like here), it looks correct. What am I doing wrong?
Upvotes: 2
Views: 1055
Reputation: 4215
The main problem is in line #5 and it's always a good idea to add the callback function for logging errors and successful requests.
var AWS = require('aws-sdk');
exports.sendAWSMail = function(message, destination){
const ses = new AWS.SES();
var data = {
Destination: {
ToAddresses: [
"[email protected]"
]
},
Message: {
Body: {
Html: {
Charset: "UTF-8",
Data: "This message body contains HTML formatting. It can, for example, contain links like this one: <a class=\"ulink\" href=\"http://docs.aws.amazon.com/ses/latest/DeveloperGuide\" target=\"_blank\">Amazon SES Developer Guide</a>."
},
Text: {
Charset: "UTF-8",
Data: "This is the message body in text format."
}
},
Subject: {
Charset: "UTF-8",
Data: "Test email"
}
},
Source: "[email protected]",
}
ses.sendEmail(data, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
}
Upvotes: 1