使用 python 处理动态电子邮件地址

发布于 2024-10-27 22:42:14 字数 1756 浏览 5 评论 0原文

我需要执行以下操作,我想知道是否有人做过类似的事情,如果有,他们做了什么。

我需要编写一个程序来处理不同客户的传入电子邮件,处理它们,然后根据电子邮件地址执行某些操作(添加到数据库、回复等)。

使这变得更具挑战性的是电子邮件地址不是静态的,而是动态的。例如。电子邮件会是这样的。 [电子邮件受保护]。电子邮件按客户端使用动态子域进行分组,在此示例中为“dynamic-subdomain1”。客户端将拥有分配给他们自己的子域。每个客户都可以在其子域下创建自己的电子邮件地址,并将事件分配给该电子邮件。这些电子邮件地址和子域可以随时更改,添加新的,删除旧的,等等。

例如,如果电子邮件进来为电子邮件 '[电子邮件受保护]' 那么我需要在数据库中查找以找出哪个客户端被分配了 'dynamic-subdomain1' 子域,然后查看哪个事件映射到 'dynamic-email1' 的电子邮件地址,然后执行该事件。我已经进行了事件处理,只是不确定如何将电子邮件地址映射到事件。

由于电子邮件地址是动态的,因此使用基于文件的配置文件来处理这个问题确实很痛苦,最好在数据库中查找。我做了一些研究,发现一些项目做了类似但不完全一样的事情。我发现的最接近的是 Zed Shaw 的 Lamson 项目:http://lamsonproject.org

更多背景:

  • 我目前正在使用 python、django、linux、mysql、memcached。

问题

  1. 有没有人使用 Lamson 来完成我想要做的事情,您感觉如何?
  2. 除了 python 之外,还有其他项目可以做类似的事情吗?也许使用不同的语言?
  3. 我该如何设置我的 DNS MX 记录来处理这样的事情?

感谢您的帮助。

更新: 我对谷歌应用程序引擎建议做了一些更多的研究,它可能会起作用,但我需要改变太多的东西,并且它会添加太多的移动部件。我还需要一个包罗万象的电子邮件转发器,有人知道有什么好的便宜的吗?我更喜欢部署在处理所有电子邮件的系统上。看起来人们已经使用 postfix 监听端口 25 并将请求转发到 lamson。这看起来很合理,我要尝试一下,看看效果如何。我将更新我的结果。

更新2: 我做了更多研究,发现了几个网站可以为我做类似的事情,所以接下来我要看看它们。

http://mailgun.net

http://www.emailyak.com

I need to do the following and I was wondering if anyone has done something similar, and if so what they did.

I need to write a program that will handle incoming emails for different clients, process them, and then depending on the email address, do something (add to database, reply, etc).

The thing that makes this a little more challenging is that the email addresses aren't static they are dynamic. For example. The emails would be something like this. [email protected] . The emails are grouped by client using a dynamic subdomain in this example it would be 'dynamic-subdomain1'. A client would have their own subdomain that is assigned to them. Each client can create their own email address under their subdomain, and assign an event to that email. These email addresses and subdomains can change all of the time, new ones added, old ones removed, etc.

So for example if an email comes in for the email '[email protected]' then I would need to look up in the database to find out which client is assigned the 'dynamic-subdomain1' subdomain and then look to see which event maps to the email address of 'dynamic-email1' and then execute that event. I have the event processing already, I'm just not sure how to map the email addresses to the event.

Since the email addresses are dynamic, it would be a real pain to handle this with file based configuration files, it would be nice to look up in a database instead. I did some research and I found some projects that do something similar but not exactly. The closest that I found is Zed Shaw's Lamson project: http://lamsonproject.org

More background:

  • I'm using python, django, linux, mysql, memcached currently.

Questions:

  1. Has anyone used Lamson to do what I'm looking to do, how did you like it?
  2. Is there any other projects that do something similar, maybe in a different language besides python?
  3. How would I setup my DNS MX record to handle something like this?

Thanks for your help.

Update:
I did some more research on the google app engine suggestion and it might work but I would need to change too many things and it would add too many moving parts. I would also need a catch all emailer forwarder, anyone know of any good cheap ones? I prefer to deploy on system that handles all email. It looks like people have used postfix listening on port 25 and forwarding requests to lamson. This seems reasonable, I'm going to try it out and see how it goes. I'll update with my results.

Update 2:
I did some more research and I found a couple of websites that do something like this for me, so I'm going to look at them next.

http://mailgun.net

http://www.emailyak.com

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

属性 2024-11-03 22:42:14

我已经使用动态电子邮件地址在几个项目上完成了一些工作,但从未同时使用动态子域。我对你的问题的看法:

  1. 我从未使用过 Lamson,所以我无法对此发表评论。

  2. 我通常使用 App Engine 的 API 来接收和处理收到消息,而且效果很好。您可以轻松地将每条收到的消息转换为您自己服务器上的基本 POST 请求,例如 ToFromSubjectMessage 字段并使用标准 django 处理这些字段。

    GAE 电子邮件的一个缺点是必须使用 *@yourappname.appspotmail.com,但您可以通过为 *@yourdomain 设置一个包罗万象的电子邮件转发器来解决这个问题。 com 将所有内容定向到 [电子邮件受保护]。这将允许您接收自定义域上的消息并使用 GAE 处理它们。

    GAE 的另一个问题/好处是使用 Google 的服务器而不是您自己的服务器(至少在电子邮件方面)。

  3. 对于子域名问题,您可以尝试为 MX 设置通配符 DNS 记录,(理论上)会将发送到任何子域的所有邮件定向到同一服务器。这将使您能够接收所有子域上的电子邮件(无论好坏 - 请注意垃圾邮件!)

I've done some work on a couple projects using dynamic email addresses, but never with dynamic subdomains at the same time. My thoughts on your questions:

  1. I've never used Lamson, so I can't comment on that.

  2. I usually use App Engine's API to receive and handle incoming messages, and it works quite well. You could easily turn each received message into a basic POST request on your own server with e.g. To, From, Subject, and Message fields and handle those with standard django.

    One downside with GAE email is having to use *@yourappname.appspotmail.com, but you could get around that by setting up a catch-all email forwarder for *@yourdomain.com to direct everything to [email protected]. That would let you receive the messages on the custom domain and handle them with GAE.

    The other issue/benefit with GAE is using Google's servers instead of your own (at least for the email bit).

  3. For the subdomain issue, you could try setting up wildcard DNS for the MX records, which (in theory) would direct all mail sent to any subdomain to the same server(s). This would enable you to receive email on all subdomains (for better or worse--look out for spam!)

情绪操控生活 2024-11-03 22:42:14

对于拉姆森,您是否尝试过像以下这样简单的事情:

@route("(address)@(subdomain).(host)", address=".+", subdomain="[^\.]+")
def START(message, address=None, subdomain=None, host=None):
    ....

For lamson, have you tried something as simple as:

@route("(address)@(subdomain).(host)", address=".+", subdomain="[^\.]+")
def START(message, address=None, subdomain=None, host=None):
    ....
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文