Finding the right abstraction; Not repeating the same mistakes You know you are in a European hotel…
Jun 10

smtp2web.com: Bridge SMTP to HTTP; Let App Engine accept Email

Google, Tech with tags: , Add comments

Nick Johnson, of Google, has created a nice bridge service smtp2web.com: Allow App Engine apps to receive email.

This is perfect timing, as after my App Engine talk in Prague, a nice gent came up to me and asked for just this. He wanted to process email in his application and didn’t think he could.

One shortcoming of purely HTTP-based webapps such as App Engine is
that they can’t receive email. I know that some people are wanting to
create App Engine apps that do this, so I put together a service to
facilitate this. It runs as a standard SMTP server, and sends all the
email it receives via HTTP POST to a user-designated URL. It’s free to
use (but not to abuse)

To use the service, you setup an email account (say dalmaer@smtp2web.com) and a URL to point too. Of course, if you want an email on your own domain you could alias dalmaer@yourdomain.com to dalmaer@smtp2web.com).

Then, you would configure an App Engine controller to receive the email contents:

from google.appengine.ext import webapp
import email
 
class EmailHandler(webapp.RequestHandler):
  def post(self):
    sender = self.request.GET.get("from", "")
    recipient = self.request.GET.get("to", "")
    message = email.message_from_string(self.request.body)
    # Do stuff with the email message

The code for the service has also been released as open source on Google Code so you can check it out. You will find that it runs as a Twisted application:

from twisted.application import service
from twisted.application import internet
from twisted.enterprise import adbapi
 
import sys
import os
sys.path.append(os.path.dirname(__file__))
 
import smtp2web
 
application = service.Application("smtp2web Service")
 
settings = smtp2web.Settings(secret_key="<enter secret key here>",
                             state_file="state", master_host="localhost:8081")
 
smtpServerFactory = smtp2web.ESMTPFactory(settings)
smtpServerService = internet.TCPServer(2025, smtpServerFactory)
smtpServerService.setServiceParent(application)

Thanks for doing this Nick!

NOTE: Mailhook is another service (pay) that does something similar

7 Responses to “smtp2web.com: Bridge SMTP to HTTP; Let App Engine accept Email”

  1. john.jones.name Says:

    thanks for the heads up it looks fairly nice and yes I like my services to be able receive and parse email so this is perfect

    regards

    John Jones
    http://www.johnjones.me.uk

  2. Nick Johnson Says:

    Thanks for the attention!

    Just an obligatory note: Though I work at Google, this (obviously) isn’t an official Google project – just something I put together in my own time. :)

  3. Johan Says:

    Hi
    I am working on an email app on GAE. How can I enable sending email with other senders than app admins?
    Johan

  4. Chandra Says:

    What are the POST parameter names? I am trying to receive the email to a ASP page?

    Thanks

  5. cnss Says:

    A silent tongue and true heart are the most admirable things on earth. http://www.laizjj.cn/

  6. Jabapyth Says:

    Wow! this is truly amazing. I hope google implements this soon ;)
    Thank you very much.

  7. farnk luis Says:

    Though I work at Google, this (obviously) isn’t an official Google project – just something I put together. i am trying to recieved the mail.to a ASP page.

Leave a Reply

Spam is a pain, I am sorry to have to do this to you, but can you answer the question below?

Q: What is the number before 3? (just put in the digit)