将发送到 AWS SES 地址的电子邮件通过管道传输到 EC2 上的 PHP 脚本 [英] Piping email sent to AWS SES address to PHP script on EC2

查看:23
本文介绍了将发送到 AWS SES 地址的电子邮件通过管道传输到 EC2 上的 PHP 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在 Amazon SES 上设置了一个域.我需要将传入的电子邮件通过管道传送到特定地址到 EC2 实例上的 PHP 脚本进行处理.我已经使用转发器在 Cpanel 中的共享服务器上完成此操作 |/opt/alt/php56/usr/bin/php -q/home/somesite/public_html/folder/somescript.php 但我我不知道如何在 SES 上设置类似的东西(如果可能的话),而且在我试图找到解决方案的过程中,谷歌并不是我的朋友.所以我的具体问题是:如何在 SES 中设置这种转发器以将传入的电子邮件通过管道传输到 EC2 上的 PHP 脚本?

We have a domain set up on Amazon SES. I need to pipe incoming emails to a specific address to a PHP script on an EC2 instance for processing. I've done this on shared servers in Cpanel using a forwarder to |/opt/alt/php56/usr/bin/php -q /home/somesite/public_html/folder/somescript.php but I'm not sure how to set up something similar (if possible) on SES, and Google has not been my friend in my attempts to find a solution. So my specific question is: how do I set up this sort of forwarder in SES to pipe incoming emails to a PHP script on EC2?

感谢您的帮助.

推荐答案

假设 SES 已设置为正确接收电子邮件,我认为您需要类似以下内容:

Assuming SES has been setup to receive the emails correctly, I think you want something like the following:

  1. 启动一个小型 ec2 实例,安装 php 和 apache,将您的 php 脚本放在公共 html 目录中(通常是 /var/www/html).目标是让其他 AWS 服务可以直接访问您的 php 脚本.

  1. Start a tiny ec2 instance, install php and apache, put your php script in the public html directory (usually /var/www/html). The goal is to make your php script accessible to other AWS services directly.

现在设置一个SES收据"规则" 导致 SNS操作" 将整个电子邮件正文转发到特定的 url,在本例中是指向您的 php 脚本的 url.

Now setup an SES "Receipt Rule" to cause a SNS "Action" that forwards the entire email body to a specific url, in this case the url to your php script.

现在 SES 收到的所有电子邮件都会触发 SNS 操作,该操作会调用您的 php 脚本,并将电子邮件正文作为脚本的参数,并且可以进行处理.

Now all emails are received by SES will triggers the SNS action which calls your php script with the email body as a parameter to your script, and it's available to process.

但是您要确保不允许外部世界访问您的 ec2 实例,因此修改安全组以仅允许来自同一子网内部的 http 请求(加上外部 ssh 连接,以便您可以管理盒子).

But you'll want to ensure that you don't allow access to your ec2 instance to the outside world, so modify the security group to only allow http requests from inside the same subnet (plus external ssh connections so you can manage the box).

对上述内容的增强是托管您的 php 脚本,该脚本将电子邮件内容作为一个函数直接在 AWS Lambda 内部处理,而无需付费运行 ec2 实例,该实例大部分时间都坐在那里什么也不做.

An enhancement to the above would be to host your php script which processes email contents as a function directly inside AWS Lambda instead of needing to pay to run an ec2 instance that is sitting there doing nothing most of the time.

Php 是一种支持 Lambda 的语言.

Php is a Lambda-supported language.

我建议首先按照我建议的方式进行操作,然后尝试将 php 脚本迁移到 Lambda 以节省资金(Lambda 对于大多数工作负载几乎是免费的,直到事情变得荒谬)

I'd recommend doing it the way I suggested at first, and then trying to migrate the php script into Lambda to save money (Lambda is pretty much free for most workloads until things get absurd)

这篇关于将发送到 AWS SES 地址的电子邮件通过管道传输到 EC2 上的 PHP 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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