在AWS Lambda函数中通过AWS SES发送电子邮件

编程入门 行业动态 更新时间:2024-10-12 01:31:29
本文介绍了在AWS Lambda函数中通过AWS SES发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在AWS Lambda上创建了一个非常基本的简单函数,该函数将用于接受表单提交.

I have created a very basic simple function on AWS Lambda which will be used to accept form submissions.

该功能的一部分将是向特定的人发送电子邮件,非常简单.我正在尝试使用AWS SES来执行此操作.我已经设置了SES服务等,并验证了我希望发送到的帐户并能够发送测试电子邮件.所有作品!!

Part of the function will be to send an email to a particular person, pretty simple. I am trying to use AWS SES in order to do this. I have setup the SES service etc, and verified the account I wish to send to and have been able to send out a test email. All works!!

现在,当我尝试在AWS Lambda中执行相同的操作并使用aws sdk时,它不会发送电子邮件.我没有收到任何错误.

Now when I try and do the same within AWS Lambda and use the aws sdk it doesn't send out the email. I don't get an error or anything.

以下是我用于AWS Lambda函数的代码.

Below is the code that I am using for the AWS Lambda function.

有人通过lambda函数使用lambda并通过ses发送电子邮件有任何经验吗?甚至只是使用node.js aws sdk很有可能会有所帮助.

Has anyone had any experience using lambda and sending emails via ses, through a lambda function? Or even just using the node.js aws sdk would more than likely be helpful.

var aws = require('aws-sdk'); var ses = new aws.SES({ accessKeyId: 'myAccessKey', secretAccesskey: 'mySecretKey', region: 'eu-west-1' }); exports.handler = function(event, context) { console.log("Incoming: ", event); var output = querystring.parse(event); var eParams = { Destination: { ToAddresses: ["toAddress@email"] }, Message: { Body: { Text: { Data: output.Key1 } }, Subject: { Data: "Ses Test Email" } }, Source: "mysource@source" }; console.log('===SENDING EMAIL==='); var email = ses.sendEmail(eParams, function(err, data){ if(err) console.log(err); else { console.log("===EMAIL SENT==="); console.log(data); } }); console.log("EMAIL CODE END"); console.log('EMAIL: ', email); context.succeed(event); };

推荐答案

似乎我将context.succeed(event)放在错误的代码区域中.

It would appear that I had the context.succeed(event) placed in the wrong area of code.

一旦将其移到sendEmail回调中,一切正常.

Once I moved it into the sendEmail callback all worked.

var aws = require('aws-sdk'); var ses = new aws.SES({ accessKeyId: 'myAccessKey', secretAccesskey: 'mySecretKey', region: 'eu-west-1' }); exports.handler = function(event, context) { console.log("Incoming: ", event); var output = querystring.parse(event); var eParams = { Destination: { ToAddresses: ["toAddress@email"] }, Message: { Body: { Text: { Data: output.Key1 } }, Subject: { Data: "Ses Test Email" } }, Source: "mysource@source" }; console.log('===SENDING EMAIL==='); var email = ses.sendEmail(eParams, function(err, data){ if(err) { console.log(err); context.fail(err); } else { console.log("===EMAIL SENT==="); console.log("EMAIL CODE END"); console.log('EMAIL: ', email); console.log(data); context.succeed(event); } });};

更多推荐

在AWS Lambda函数中通过AWS SES发送电子邮件

本文发布于:2023-11-23 20:07:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1622728.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   发送电子邮件   AWS   Lambda   SES

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!