django rest-auth注册返回“已发送验证电子邮件”,但未发送电子邮件,也未发送/返回密钥

问题描述

我是 django,django-rest-framework,django-allaut和dj-rest-auth 的新手。我正在使用邮递员注册用户,该用户已成功保存到数据库中,并且我收到一条消息

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

我的电子邮件配置如下(两者均无法发送电子邮件验证): 第一次尝试

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

然后尝试:

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

在我的项目应用程序中,urls.py:

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

帐户应用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?

解决方法

我从PolishCoder那里得到了解决方案

最初,我认为这是由于配置错误所致。