Using Gmail's SMTP server from Django
Ever since changeset 5144 Django has had the ability to send email directly through Gmail with a few extra settings in your settings.py file. I recently set up a server using Ubuntu and had no intention of receiving email on it, but I did, however, want my website to be able to send email, so this is a great solution for that case.
Gmail
Consider creating a new email account from which the email will be sent. I like to do this for a few reasons:
-
For security reasons I don't want to list my password of my main Google Apps account holder in my
settings.pyfile. Setting up a secondary account using an address likeinfo@orwebmaster@with a generated password felt like the right approach for me. - Using a secondary account also has the benefit of separating any replies to website emails. You can set up filters on the website email account and forward them to your main account holder easily enough.
Django
Here are the settings as I've listed them in my settings.py file:
EMAIL_HOST = 'smtp.gmail.com' EMAIL_HOST_USER = 'USER@YOUR_DOMAIN.com' EMAIL_HOST_PASSWORD = 'YOUR_PASS' EMAIL_PORT = 587 EMAIL_USE_TLS = True
I'm also setting SERVER_EMAIL and DEFAULT_FROM_EMAIL to the same address as EMAIL_HOST_USER but for clarity of the above, chose not to show those settings.
It's great that Django comes pre-baked to support any mail server that requires TLS connections like Gmail.
About this entry
Date Posted:
August 31st 2008 at 11:08:28 PM
Previous Entry:
Django and Relativity
Next Entry:
Introducing the Django Debug Toolbar
Comments
blog comments powered by Disqus