Articles → NODE.JS → Send An Email By Calling Amazon SES Using Node.Js
Send An Email By Calling Amazon SES Using Node.Js
Steps
- Generate access and secret keys of the user.
- Verify email addresses (sender and receiver) in SES.
- Add user credential in the "credentials" file.
- Write code to send an email.
- Output.
Generate Access And Secret Keys Of The User
Verify Email Addresses (Sender And Receiver) In SES
Click to Enlarge
Add User Credential In The “Credentials” File
c:\users\<username>\.aws\credentials
Click to Enlarge
Write Code To Send An Email
var aws = require('aws-sdk');
aws.config.getCredentials(function (err) {
if (err) console.log(err.stack);
else {
//console.log("Access key:", aws.config.credentials.accessKeyId);
}
});
var ses = new aws.SES({
region: 'ap-south-1'
});
handler = function () {
//console.log("Incoming: ", event);
var eParams = {
Destination: {
ToAddresses: ["recipient@gmail.com"]
},
Message: {
Body: {
Text: {
Data: "Lambda is working"
}
},
Subject: {
Data: "Mail From SES"
}
},
Source: "sender@gmail.com"
};
console.log('===Sending Email====');
var email = ses.sendEmail(eParams, function (err, data) {
//console.log(eParams);
if (err) console.log(err);
else {
console.log('===Email Sent====');
//context.succeed(event);
}
});
};
handler();
Output
Click to Enlarge