Snippets: Test Email Sending in Django

This is what I do when I want to test if sending of emails from a Django web app works.

First, in the project directory, I launched a manage shell session.

$ python manage.py shell

Then I entered the following commands.

Python 2.7.5 (default, Nov 20 2015, 02:00:19)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from django.core.mail.message import EmailMessage
>>> e = EmailMessage('S', 'M', 'noreply@domain.com', ['dar@domain.com'])
>>> e.send()
1
>>>

A return of 1 means it’s working. A second later, the email came.

It works!

Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *