使用AWS API Gateway通过AWS SES POST电子邮件 [英] Using AWS API Gateway to POST email via AWS SES

查看:204
本文介绍了使用AWS API Gateway通过AWS SES POST电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从一个应用程序中设置一个API,该API允许该应用程序的用户与某人联系以进行跟进,但隐藏发件人的电子邮件地址(并允许在不发行该新版本的应用程序的情况下对其进行更改).

I'm setting up an API from an App which allows the App user to contact someone for follow-up, but hides the email address from the sender (and allows it to be changed without a new release of the App).

我设法设置了一个AWS API Gateway GET方法,该方法直接通过SES发送电子邮件

I've managed to setup an AWS API Gateway GET method which sends email directly via SES

https://...aws.com/em/send/en?body=The+email+is+here

使用路径替代

Action=SendEmail
&Source=source%40mydomain.org
&Destination.ToAddresses.member.1=follow.up%40anydomain.com
&Message.Subject.Data=Request+For+Followup
&Message.Body.Text.Data={body}

我更喜欢使用 POST 方法-但实际上很难弄清楚Action参数应包含的内容以及如何创建映射模板-甚至即使它尽管AWS文档中确实包含了$util.urlEncode()函数,但无需诉诸lambda函数就可以创建application/x-www-form-urlencoded请求.

I would much prefer to use a POST method - but am really struggling to work out what should go in the Action parameter and how to create the mapping template - or even if it is possible to create an application/x-www-form-urlencoded request without having to resort to a lambda function - although the AWS documentation does include a $util.urlEncode() function.

http://docs .aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html

我正在尝试对AWS Gateway使用POST方法,对请求正文中的内容使用POST到SES,但是我不清楚如何创建映射模板,并且找不到任何示例SES.

I am trying to use a POST method to AWS Gateway and a POST to SES with the contents in the request body, but it is just not clear to me how to create the mapping template and I can't find any examples for SES.

使用映射模板对其进行测试(按照

Testing it with the mapping template (as per the example in the documentation)

Source=source%40mydomain.org
&Destination.ToAddresses.member.1=follow.up%40anydomain.com
&Message.Subject.Data=Request+For+Followup
&Message.Body.Text.Data=The+message+goes+here

并且内容类型application/x-www-form-urlencoded AWS网关给出错误:

And a content type application/x-www-form-urlencoded AWS gateway gives the error:

{
"message": "Unsupported Media Type"
}

如果我使用映射模板

{
"Action":"SendEmail",
"Source":"source@mydomain.org",
"Destination":{
    "ToAddresses":{
        "member":["follow.up@anydomain.com"]
        }
    },
"Message":{
    "Subject": {
        "Data":"Request For Followup"
        },
    "Body":{
        "Text":{
            "Data":"The message goes here"
            }
        }
    }
}

并且内容类型为application/json AWS Gateway会给出错误

and a content type of application/json AWS gateway gives the error

{
  "Output": {
    "__type": "com.amazon.coral.service#UnknownOperationException",
    "message": null
  },
  "Version": "1.0"
}

推荐答案

您的映射模板配置必须为POST格式,而不是JSON格式,因为SES服务不支持json(

Your mapping template configuration must be in a POST format, not in the JSON, since SES service doesn't support json (https://docs.aws.amazon.com/ses/latest/DeveloperGuide/query-interface-examples.html) for example this config has worked out for me

Action=SendEmail&
Message.Body.Text.Data=Some+text&
Message.Subject.Data=New+message&
ReturnPath=some@mail.io
&Destination.ToAddresses.member.1=some@destination.com
&Source=your@sender.email

此外,仅在上述情况下,您的路径覆盖率必须为SendEmail

Also, your path override must be SendEmail only for the case above

这篇关于使用AWS API Gateway通过AWS SES POST电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆