Skip to content

Instantly share code, notes, and snippets.

@aniket91
Created August 16, 2018 15:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save aniket91/799e3c8a6132b79f6e35b0c8a99f7742 to your computer and use it in GitHub Desktop.
Save aniket91/799e3c8a6132b79f6e35b0c8a99f7742 to your computer and use it in GitHub Desktop.
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