0
votes

I am new to django, django-rest-framework, django-allaut and dj-rest-auth. I am using postman to register a user, the user gets saved successfully in the database, and I get a message saying

{
    "detail": "Verification e-mail sent."
}

My email configurations is as follows (Both did not work in sending the email verification): First tried

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.mailtrap.io'
EMAIL_HOST_USER = {{my_mailtraip_user}}
EMAIL_HOST_PASSWORD = {{my_mailtraip_pass}}
EMAIL_PORT = '2525'
EMAIL_USE_TLS = True

Then tried:

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = {{my_gmail_address}}
EMAIL_HOST_PASSWORD = {{my_gmail_password}}
EMAIL_PORT = 465
EMAIL_USE_TLS = True

in my projects app, urls.py:

path('api/accounts/', include('account.urls')),
path('api/accounts/', include('allauth.urls')),

accounts app urls.py:

    path('dj-rest-auth/', include('dj_rest_auth.urls')),
    path(
        'dj-rest-auth/registration/',
        include('dj_rest_auth.registration.urls')
    ),
    path('dj-rest-auth/account-confirm-email/',
        VerifyEmailView.as_view(), 
        name='account_email_verification_sent'
    ),

settings.py

SITE_ID = 1
ACCOUNT_EMAIL_REQUIRED=True
ACCOUNT_EMAIL_VERIFICATION = 'mandatory'
REST_USE_JWT = True

INSTALLED_APPS = [
    ...

    'django.contrib.messages',
    'django.contrib.sites',

    ...

    'rest_framework',
    'rest_framework.authtoken',

    'allauth',
    'allauth.account',
    'allauth.socialaccount',

    'dj_rest_auth',
    'dj_rest_auth.registration',
]

REST_FRAMEWORK = {
    'DEFAULT_PERMISSION_CLASSES': (
        'rest_framework.permissions.IsAuthenticated',
    ),
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework_simplejwt.authentication.JWTAuthentication',
    ),
}
AUTHENTICATION_BACKENDS = (
   "django.contrib.auth.backends.ModelBackend",
   "allauth.account.auth_backends.AuthenticationBackend",
)

What am I missing or failing to understand? Why is the email not sent to mailtrap? Why am not getting the key?
1

1 Answers

0
votes

I got the solution from PolishCoder

Initially I thought it was due to some mis-configuration.