Add outbound email to your app

The GAE email service takes the form of “mail.send_mail(FROM, TO, SUBJECT, TITLE)” so I decided to use my blog form and add two further input fields for the From and To post input parameters. I just copied the original blog html form and added the two additional input fields, quite simple.

First off you must import the email function as such:

from google.appengine.api import mail

I created a new AppEmail class by copying my old NewBlog posting Class and making the following changes by adding this code;



I then added additional parameter error handling as such;

if user_from =="":

params['error_from'] = "Please enter an admin email adress"

have_error = True

if user_to =="":

params['error_from'] = "Please enter a valid email adress"

have_error = True

Finally I needed to add the actual send email code as such;


if user_from !="" and user_to!="" and user_title != "" and user_content !="":


self.response.out.write('email sent')

And that’s it, except the first time I deployed I had forgot to add the mail.send_mail function as above and wondered why the email did not come through! A couple of points to remember.

The from email adress must be either from the GAE registered email account holder or an app administrator email account that was added to the app or an email from the app itself whereby it is in some form of valid email adress for the app such as

Secondly there is an email limit before the charges start kicking in so you may want to check that as well. I think it is 100 per cycle but best check your app quota in the dashboard. Here is the link to the docs on Google, happy coding!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s