Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django rest auth email validation

Can someone explain how to set up email verification for django rest auth ? My settings.py contains:

EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
ACCOUNT_EMAIL_VERIFICATION = 'mandatory'
ACCOUNT_AUTHENTICATION_METHOD = 'email'
ACCOUNT_EMAIL_REQUIRED = True   
ACCOUNT_USERNAME_REQUIRED = False

And I've added this line in my urls.py:

url(r'^accounts/', include('allauth.urls')),

But when I register with this endpoint: rest-auth/registration/, the email is not sent, but the user is created. What is the good configuration to send email confirmation? Do I have to have a SMTP server?

EDIT: (after @McAbra comment)

Obviously, this setting cannot send email:

EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

It only print the mail in the django console output. The settings given by @McAbra works well. But in a production environment, is it a good practice to send verification email with gmail? Have I just to create email such [email protected]?

EDIT 2:

My other problem is that the sent mail is empty. The template are presents in site-packages\allauth\templates\account\email. The email title is [http://localhost:8000/] but there is no content. I have no error in the python console. Any idea?

Solution for this point:

site-packages\allauth\templates\account\email files must be copied in your-app\templates\account\email

like image 784
Ben Avatar asked Oct 11 '16 17:10

Ben


Video Answer


2 Answers

You need to have a SMTP server if you want to send real emails. I like to use Gmail SMTP server. settings.py would be:

EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = 'gmail_username'
EMAIL_HOST_PASSWORD = 'password from https://security.google.com/settings/security/apppasswords'

Try from there. I'll try to help further if that doesn't help.

like image 154
McAbra Avatar answered Oct 12 '22 08:10

McAbra


I had problems with sending emails and after that with the link in the email. You need to explicitly set the account confirm email view.

Below are my settings in settings.py

 ACCOUNT_AUTHENTICATION_METHOD = 'email'
 ACCOUNT_EMAIL_REQUIRED = True   
 ACCOUNT_USERNAME_REQUIRED = False
 ACCOUNT_EMAIL_VERIFICATION = 'mandatory'

in urls.py

  from allauth.account.views import confirm_email as allauthemailconfirmation

  urlpatterns  = [
  url(r'^api/rest-auth/account-confirm-email/(?P<key>[-:\w]+)/$',allauthemailconfirmation,
    name='account_confirm_email'),
  ]

You can use mailcatcher.me if you want to check emails locally.

like image 23
sarc360 Avatar answered Oct 12 '22 07:10

sarc360