使用AWS API Gateway通过AWS SES发送电子邮件

时间:2017-01-21 11:04:46

标签: amazon-web-services aws-api-gateway amazon-ses

我正在从应用程序设置API,允许应用程序用户联系某人进行跟进,但隐藏发件人的电子邮件地址(并允许在没有新版本的应用程序的情况下更改)。

我设法设置了一个AWS API Gateway GET方法,该方法通过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参数中的内容以及如何创建映射模板 - 或者即使可以创建application/x-www-form-urlencoded请求而不必求助于lambda函数 - 尽管AWS文档确实包含$util.urlEncode()函数。

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

修改

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

使用映射模板对其进行测试(根据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网关提供错误:

{
"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网关提供错误

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

1 个答案:

答案 0 :(得分:0)

您的映射模板配置必须采用POST格式,而不是JSON格式,因为SES服务不支持json(https://docs.aws.amazon.com/ses/latest/DeveloperGuide/query-interface-examples.html),例如,该配置已为我解决

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