Django logoI mentioned previously that I'm working on a Pinax project. Email notifications are one of the things you need to get working in your development environment. Unfortunately for the novice Django developer, getting this working may not be obvious.

Pinax uses an application called django-mailer to handle outgoing email. This is a drop-in replacement for the mail functions built into Django. The first thing I needed to get a handle on was how to get django-mailer to send mail. The theory is that mail is queued inside the database, and then is sent when instructed via the appropriate manage.py sub-command. According to the django-mailer Quick Start Guide, there are two sub-commands:

  • send_mail - attempt to send any mail in the queue.
  • retry_deferred - put deferred mail back into the queue. It's important to note here that retry_deferred does not try to deliver the deferred mail. It just makes it available to send_mail again.

So, in order to get queued mail sent, simply run ./manage.py send_mail. Simple enough. The Quick Start Guide recommends running this from cron every minute. That's reasonable in a production environment, but probably unnecessary in development.

By default, Django and django-mailer use the local system as their SMTP server. This might not be appropriate for your situation. Here are the settings you can drop in your localsettings.py file to get your development environment working properly:

  • EMAIL_HOST
  • EMAIL_HOST_PASSWORD
  • EMAIL_HOST_USER
  • EMAIL_PORT
  • EMAIL_USE_TLS

If you're lucky, you have a static mail server somewhere that runs on a port other than 25 (465, for example) and uses encrypted authentication. This will let you develop your Pinax application from anywhere!