7

I am developing a django application on my MAC. The development server that comes with django is great. However, I installed the django-authopenid (combines django-registration app with openID) which follows the 3 step process: user signs up, app sends a confirmation email with link, and user clicks on link to confirm sign-up.

Since the django development server does not have a mail server, how do I test this confirmation email portion of the process? I followed an idea to print out the contents of the email to the terminal, but I can't follow the link. Any suggestions?

rich
  • 595
  • 1
  • 7
  • 15

4 Answers4

14

Python has a debugging mail server available for this purpose.

Just execute this command and you'll have a mailserver running at port 1025

python -m smtpd -n -c DebuggingServer localhost:1025

After that you'll need to change your MAIL_HOST setting in Django and you can test your emails locally :)

Wolph
  • 78,177
  • 11
  • 137
  • 148
9

If you have a Gmail account, you can use it to send your dev mail. Put the following in your settings.py file:

# django-registration
ACCOUNT_ACTIVATION_DAYS = 7
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'YourEmail@gmail.com'
EMAIL_HOST_PASSWORD = 'YourGmailPassword'
EMAIL_PORT = 587
DEFAULT_FROM_EMAIL = 'DevBox <YourEmail@gmail.com>'
LOGIN_REDIRECT_URL = '/'
mitchf
  • 3,697
  • 4
  • 26
  • 29
5

The following additions to settings.py will make it so all emails sent by your django apps are written to <PROJECT_ROOT>/dev/email/ (or choose another directory):

# I put this at the top of all my settings.py files
import os
ROOT = os.path.dirname(os.path.abspath(__file__))

# Somewhere later
EMAIL_BACKEND = 'django.core.mail.backends.filebased.EmailBackend'
EMAIL_FILE_PATH = path(ROOT, "dev", "email")
David Marble
  • 1,867
  • 1
  • 16
  • 10
0

I personally love django-extensions (https://github.com/django-extensions/django-extensions)

It adds a manage.py command called 'mail_debug' that does what WoLpH recommended automatically.

It also comes with a ton of other great debugging and dev tools like runserver_plus, show_template, show_urls, etc... (I really wish django-extensions would get rolled into Django already!)

Aaron C. de Bruyn
  • 2,347
  • 1
  • 30
  • 40