How to test django application registration process during server development (no mail)

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

Since the django development server does not have a mail server, how to check this part of the email confirmation process? I followed the idea of โ€‹โ€‹printing the contents of the letter to the terminal, but I can not follow the link. Any suggestions?

+6
django email registration
source share
4 answers

Python has a debug mail server for this purpose.

Just run this command and you will have a mail server running on port 1025

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

After that, you will need to change your MAIL_HOST parameter in Django, and you can check your email addresses locally :)

+12
source share

If you have a Gmail account, you can use it to send your email. Add the following to 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 = '/' 
+9
source share

The following additions to settings.py will make sure that all emails sent by your django applications are recorded in <PROJECT_ROOT>/dev/email/ (or choose a different 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") 
+5
source share

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

He adds a manage.py command named "mail_debug" that automatically runs WoLpH.

It also includes subtle other great debugging and dev tools like runerver_plus, show_template, show_urls, etc. (I really want the django extensions to already merge into Django!)

0
source share

All Articles