I 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 thatretry_deferred
does not try to deliver the deferred mail. It just makes it available tosend_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!
In development, I don't normally send email at all but manually inspect the mailer queue in the django admin.
FWIW, here are the settings to use a Gmail account:
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'account@gmail.com'
EMAIL_HOST_PASSWORD = 'PASSWORD'
EMAIL_USE_TLS = True
Thanks for the tip, Chris!
I found your blog on google and read a few of your other posts. I just added you to my Google News Reader. Keep up the good work. Look forward to reading more from you in the future.
Thanks for this blog. I am new at django and this is a big help.
Truly efficiently set.