Triggering 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."
   }
  }
 });

};

Comments

Popular posts from this blog

AWS LEX - Developing a Simple Chat Bot

Connecting Mongo DB with NodeJS

BUILDING A CHAT BOT USING MICROSOFT AZURE BOT SERVICE & LUIS