Saturday, June 8, 2013

Outbound email from Django on the App Engine dev server

Once everything is configured as described in my previous post, your code will run. But you won't be able to send outbound email from the App Engine dev server.

If you just want to see the email output but don't need it actually sent, you can simply enable the --show_mail_body flag when you launch the dev server and it'll just dump the contents out to the console. --show_mail_body mygaeproject

Wish I'd known that a few hours ago. Grumble.

But since we're here and I did eventually figure it out, here's how you can enable SMTP relaying from the local dev server out through a Gmail account:

Gmail access
Set up an "application-specific password" for your Gmail account that will only be used by your local dev server. Info is here and is pretty straightforward. Keep the 16-character password that is generated for you handy.

Avoid port 25
The default email port is blocked by a lot of ISPs, mine included. Instead use the alternate port 587.

Enable TLS
I have no clue what that is, but you won't be able to SMTP through Gmail without it. Patch the App Engine code to support it as described here. Note: each time you download a new version of the App Engine API you will have to re-patch this bit of code.

Launch the dev server with SMTP relaying
Use the SMTP option flags when you start the local server: --smtp_port=587 --smtp_password=16_char_app_password mygaeproject

Make a launcher script
That's a bunch to type so save yourself the trouble and go to your mygaeproject/src dir and create a simple script: nano

Paste the above call in and save the file.

Make the script executable: chmod 700

Then execute it with: ./