0

Can someone give me a working example code? I use NodeJS v6.14.4 Below is my pseudo code.

I am new to NodeJS. If someone can provide a working sample code to at least send out SES email from a node JS as a reusable user function then that would be great.

I am looking to structure my NodeJS code like this manner: --------------index.js----------------------------- initialize aws library.

exports.handler = function(event, context) {

    // Read the invoking SQS queue.
    var queueType = getQueueType(SQL_URL);

    // Send customer welcome email for Reseller Type ='RS'  
    if(queueType == 'RS') {
       SendSESEmailRS(params);
    }

    // Send customer welcome email for Reseller Type ='EY'  
    if(queueType == 'EY') {
       SendSESEmailEY(params);
    }


}

function SendSESEmailRS(params){
   // code to send out SES Email
}

function SendSESEmailEY(params){
   // code to send out SES Email
}    

// Get the Reseller type from the invoking queue.
function getQueueType(params){
   // code to retrieve the Reseller shortForm from the SQS queue which is invoking this Lambda Function.
}
John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
jcoder
  • 117
  • 1
  • 12

2 Answers2

0

Here I made a simple solution for you. Go here https://github.com/mdhelaluddin-ctg-bd/ses-email-nodejs

Download these code from Github. Install and configure by reading the readme.md instruction. It's easy.

create another file for lambda function. put the 'require' (npm packages) parts to the header and remaining part inside the exports.handler = function(event, context) { } function. Then create a zip of this project folder and upload as in lambda function as as zip...

Then DONE !!!

Feel free to ask at comment if you face any further problems. Thanks

Md. Helal Uddin
  • 1,943
  • 1
  • 14
  • 18
  • Hi thanks for the reply. Could you kindly give the code for this part "put the 'require' (npm packages) parts to the header and remaining part inside the exports.handler = function(event, context) { } function" . Sorry I am totally new to NodeJS, and just signed up for an online course to learn Node. Some of the terms I am still trying to understand. I have installed your ses-email bundle from Git. – jcoder Sep 30 '18 at 13:53
  • I meant this part -- require('dotenv').config() const AWS = require('aws-sdk'); const ses = new AWS.SES(); -- – Md. Helal Uddin Oct 01 '18 at 02:07
  • @jcoder let me know if you understand or not what I meant – Md. Helal Uddin Oct 01 '18 at 02:09
  • No I did not use your library. I managed to implement the whole solution just by using NPM nodemailer and NodeJS AWS SDK – jcoder Oct 16 '18 at 03:18
0

I like to use nodemailer library to deal with different kind of emailing. Few links for you with examples:

Max Vinogradov
  • 1,343
  • 1
  • 13
  • 31