While Python AppEngine documentation give a good example on receiving email on AppEngine, but for me it take time to figure out how to do that in Django.
For those who haven’t yet figure out how to do that, let me save your time.
Configuring Your App to Receive Email
Incoming email is disabled by default. To enable the incoming email service, you must add a few lines in your app.yaml
inbound_services: - mail
If your project name is example, your application can receive email at addresses test@example.appspotmail.com
Now your incoming email service is enable, you need to understand that incoming emails are sent to your application as POST request using URL :
/_ah/mail/address
So in your Django project you need to add url to receive messages sent by the incoming email service.
urlpatterns = patterns('', ... (r'^_ah/mail/test@example.appspotmail.com$', 'example.views.email_handler') )
Handling Incoming Email
After setting your configuration to receive email, now we need to create view to handle incoming email.
import logging from django.views.decorators.csrf import csrf_exempt from google.appengine.api import mail @csrf_exempt def email_handler(request): if request.POST: message = mail.InboundEmailMessage(request.raw_post_data) logging.info("Received a message from: " + message.sender) return HttpResponse('ok')
That’s it. Have fun with AppEngine and Django.
Related posts:
- Sending Email Using Gmail Account in Django
- Using django-paypal IPN in Django 1.2
- Django Tutorial – Simple Notes Application
- Email Validation Challenge
- 10 Django Apps I Can’t Live Without
Tags: app engine, django
June 30th, 2010 | Comments(5)

[...] This post was mentioned on Twitter by KomunitasWeb. KomunitasWeb said: New blog posting, Receiving Email Using AppEngine and Django – http://tinyurl.com/2c7gcn4 [...]
Pingback by Tweets that mention Receiving Email Using AppEngine and Django | KomunitasWeb -- Topsy.com — June 30, 2010 @ 9:03 pm
Awesome tutorial that has made me think of adding a feature I wanted to for a while. Thanks! Do you know how to do this under django, but not running on app engine?
Comment by Alex — July 28, 2010 @ 11:50 pm
New blog posting, Receiving Email Using AppEngine and Django – http://tinyurl.com/2c7gcn4
This comment was originally posted on Twitter
Comment by komunitasweb — June 30, 2010 @ 7:34 am
Receiving Email Using AppEngine and Django | KomunitasWeb: Google AppEngineで稼働するDjangoアプリケーションでメールを受信する方法 http://bit.ly/b0B8ve
This comment was originally posted on Twitter
Comment by Inetgate — June 30, 2010 @ 7:19 pm
Receiving Email Using AppEngine and Django | KomunitasWeb: http://bit.ly/d4D4Vr
This comment was originally posted on Twitter
Comment by djangostories — June 30, 2010 @ 9:30 pm