You can handle emails that have been send to “whatever@app-id.appspotmail.com” in your Python code. Here’s how:
1. Edit your app.yaml file
You need to update two sections here:
inbound_services:
- mail
handlers:
- url: /_ah/mail/.+
script: handle_mail.py
login: admin
When an email is sent to you, a post request to “/_ah/mail/{full_address}” is made and handled by the handle_mail script. The “login: admin” is not a problem as the request is made by the server with admin privileges.
2. Add code that handles the incoming email
from google.appengine.ext import webapp from google.appengine.ext.webapp.mail_handlers import InboundMailHandler from google.appengine.ext.webapp import util import email class LogSenderHandler(InboundMailHandler): def receive(self, mail): # Handle mail here application = webapp.WSGIApplication([LogSenderHandler.mapping()], debug=True) def main(): util.run_wsgi_app(application) if __name__ == '__main__': main()
You can easily get the sender’s email address and the subject of their email from the InboundEmailMessage object, i.e. the mail argument. Use its “subject” and “sender” properties and try to send an email via the “Inbound Mail” form in the SDK Console.
3. Get more info about the email
To get the email body you can use the bodies() method of the mail parameter. You can also get a string with all the important information by calling mail.original.as_string().
There is no quota on the number of emails you receive, it just counts to your quotas for CPU, bandwidth etc.
