开发者

Process dynamic email addresses using python

开发者 https://www.devze.com 2023-02-20 09:08 出处:网络
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 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. dynamic-email1@dynamic-subdomain1.domain.com . 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 'dynamic-email1@dynamic-subdomain1.domain.com' 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


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 secretaddress@yourappname.appspotmail.com. 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!)


For lamson, have you tried something as simple as:

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

精彩评论

暂无评论...
验证码 换一张
取 消