Instantly share code, notes, and snippets.

Embed
What would you like to do?
Node.js code snippet to send email using AWS SES service
const aws = require('aws-sdk');
aws.config.loadFromPath('./config.json');
const ses = new aws.SES();
/**
* author: athakur
* aws ses create-template --cli-input-json fileb://test_template.json --region us-east-1 --profile osfg
* aws ses update-template --cli-input-json fileb://test_template.json --region us-east-1 --profile osfg
* @param {*} callback
*/
var sendMail = function (callback) {
var params = {};
var destination = {
"ToAddresses": ["opensourceforgeeks@gmail.com"]
};
var templateData = {};
templateData.userName = "athakur";
params.Source = "opensourceforgeeks@gmail.com";
params.Destination = destination;
params.Template = "testtemplate";
params.TemplateData = JSON.stringify(templateData)
ses.sendTemplatedEmail(params, function (email_err, email_data) {
if (email_err) {
console.error("Failed to send the email : " + email_err);
callback(email_err, email_data)
} else {
console.info("Successfully sent the email : " + JSON.stringify(email_data));
callback(null, email_data);
}
})
}
sendMail(function(err, data){
if(err){
console.log("send mail failed");
}
else {
console.log("Send mail succedded");
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment