Created
August 16, 2018 15:32
-
-
Save aniket91/799e3c8a6132b79f6e35b0c8a99f7742 to your computer and use it in GitHub Desktop.
Node.js code snippet to send email using AWS SES service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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