Trigger an Email using AWS Lambda with the help of AWS SES

Using the Amazon Web Services to Trigger an email.

Here we have used AWS SES service.

Firstly you have to register senders email address in AWS SES app in AWS then after confirmation, you can use the SES service in Lambda.

Node JS Code for Lambda:

var aws = require("aws-sdk");

var ses = new aws.ses({
 region:'us-east'
});

exports.handler = (events,context,callback) => {
 
 var emailID = "receiversemail@email.com"

  var eParams = {
   
   Destination:{
    
    ToAddresses: [emailID]
   },
   
   Message:{
    
    Body:{
     
     Text:{
      
      Data: "Hi, How are You?"
     }
    },
    Subject:{
     
     Data: "Hello."
    }
   },
   
   Source: "sendersemail@email.com"
 };
 
 var email = ses.sendEmail(eParams, function(err, data)
 {
  if(err){
   console.log("error");
  }
  else{
   console.log("email sent");
  }
 });
 
 
 callback(null,{
  
  "dialogAction":{
   
   "type": "close",
   "fullfillmentState":"Fullfilled",
   "message":{
    "contentType":"PlainText",
    "content" : "Thank You! A email has been sent."
   }
  }
 });

};
Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s