【问题标题】:How to send out SES email from a Lambda NodeJS?如何从 Lambda NodeJS 发送 SES 电子邮件?
【发布时间】:2019-03-05 03:53:20
【问题描述】:

谁能给我一个工作示例代码?我使用 NodeJS v6.14.4 下面是我的伪代码。

我是 NodeJS 的新手。如果有人可以提供一个工作示例代码,以至少从节点 JS 发送 SES 电子邮件作为可重用的用户函数,那就太好了。

我希望以这种方式构建我的 NodeJS 代码: --------------index.js------------------ 初始化 aws 库。

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.
}

【问题讨论】:

    标签: node.js amazon-web-services aws-lambda amazon-sqs amazon-ses


    【解决方案1】:

    在这里,我为您做了一个简单的解决方案。到这里 https://github.com/mdhelaluddin-ctg-bd/ses-email-nodejs

    从 Github 下载这些代码。通过阅读 readme.md 指令进行安装和配置。这很容易。

    为 lambda 函数创建另一个文件。将 'require' (npm packages) 部分放到 exports.handler = function(event, context) { } 函数的标题中。然后创建此项目文件夹的 zip 并像 lambda 函数一样作为 zip 上传...

    然后完成!!!

    如果您遇到任何进一步的问题,请随时在评论中提问。谢谢

    【讨论】:

    • 您好,感谢您的回复。您能否提供这部分的代码“将 'require' (npm 包) 部分放在头文件中,其余部分放在 exports.handler = function(event, context) { } 函数中”。抱歉,我对 NodeJS 完全陌生,刚刚注册了一个在线课程来学习 Node.js。我仍在努力理解一些术语。我已经从 Git 安装了你的 ses-email 包。
    • 我的意思是这部分 -- require('dotenv').config() const AWS = require('aws-sdk');常量 ses = 新 AWS.SES(); --
    • @jcoder 让我知道你是否理解我的意思
    • 不,我没有使用你的图书馆。我设法通过使用 NPM nodemailer 和 NodeJS AWS SDK 来实现整个解决方案
    【解决方案2】:

    我喜欢使用 nodemailer 库来处理不同类型的电子邮件。 几个链接给你的例子:

    【讨论】:

      猜你喜欢
      • 2016-11-17
      • 1970-01-01
      • 2019-12-13
      • 2020-01-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-25
      相关资源
      最近更新 更多