Django Allauth (3) – Email Verification via Console
This lesson will explain how to set up email verification using a console (terminal) in the development environment.
1. Edit settings.py
The console-based email verification setting is easy to implement. You just need to edit the two lines of code in settings.py.
- Change
ACCOUNT_EMAIL_VERIFICATION
from "none" to "mandatory
" - Add
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
in the end of settings.py
The second setting enables Django to display email contents in the console.
ACCOUNT_AUTHENTICATION_METHOD = "email"
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_EMAIL_VERIFICATION = "mandatory"
:
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
2. Check the results
To check the results, try to sign up again. You can use a dummy email, as no email will be actually sent.
Once you hit the Sign Up button, you'll see the message below...
...and you'll get a virtual email in your terminal like the one below. Go to the URL to see the result.
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: [example.com] Please Confirm Your E-mail Address
From: webmaster@localhost
To: xxxxx@gmail.com
Date: Fri, 07 Apr 2023 14:53:30 -0000
Message-ID:
<168087921091.20140.5593477130948205989@macbook-pro.myrepublic.com.sg>
Hello from example.com!
You're receiving this e-mail because user xxxxx has given your e-mail address to register an account on example.com.
To confirm this is correct, go to http://localhost:8000/accounts/confirm-email/MTY:1pknT0:wDqaqGgeBGx6IMkF76NQU9n8tyVsrqpJC1fXFtKJ9fE/
Thank you for using example.com!
example.com
On the browser, you'll find the email confirmation message. Once you press the Confirm button, your account will be created...
...and you'll be ready to sign in (log in) to the service.
Sign in with your registered email and password. You'll jump to the home page (You are successfully logged in to the app).