5

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

Ken Cochrane
  • 75,357
  • 9
  • 52
  • 60

2 Answers2

1

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!)

Greg Haskins
  • 6,714
  • 2
  • 27
  • 22
  • Thanks for the App Engine suggestion, I thought about app engine, but I wasn't sure how to do it with the appspotmail.com email address restriction, I'll have to try it out for the forward and see if it will work. The one problem is that my normal emails blah@mydomain.com would also go to appengine as well. It doesn't look like there is a rate limit for incoming email, which is good as well. – Ken Cochrane Mar 30 '11 at 13:41
  • 1
    Yeah, I thought about the "regular" email issue, too. Maybe the wildcard record could point subdomains to e.g. `app_mail.mydomain.com` with the catch-all on that (instead of on the bare domain)? If the subdomain issue gets too complicated, it might be worth considering an alternate syntax, like `user+command@mydomain.com` if that makes things easier. – Greg Haskins Mar 30 '11 at 15:36
  • The way the app works now it has heavy use of subdomains, but I'll see if I can work around that to try your user+command@mydomain.com approach, it does make things a little cleaner, but I'm guessing I might have to do user+commands@incoming.mydomain.com or something similar so that my regular @mydomain.com emails aren't sent to the same MX server as the automated ones. Thanks for the suggestion. – Ken Cochrane Apr 01 '11 at 13:21
0

For lamson, have you tried something as simple as:

@route("(address)@(subdomain).(host)", address=".+", subdomain="[^\.]+")
def START(message, address=None, subdomain=None, host=None):
    ....
EoghanM
  • 25,161
  • 23
  • 90
  • 123