注册 rest-auth 后 Django 不发送电子邮件
Django is not sending email after rest-auth registration
在我将用户模型更改为使用电子邮件而不是用户名后,当我访问 rest-auth.registration.views.RegisterView
时电子邮件没有发送。
我应该怎么做才能工作?
我的电子邮件设置是:
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
这是正确的配置,在 rest_auth.views.PasswordResetView
上发送电子邮件工作正常。
我的代码:
users/urls.py:
app_name = "users"
urlpatterns = [
path("register/", include("rest_auth.registration.urls")),
...
]
config/urls.py:
from allauth.account.views import AccountInactiveView
urlpatterns = [
...
path("api/v1/users/", include("myproject.users.urls")),
# this url is used to generate email content
# https://github.com/Tivix/django-rest-auth/blob/master/demo/demo/urls.py
path("password-reset/<uidb64>/<token>/", TemplateView.as_view(), name="password_reset_confirm")
# for some reason required for rest-auth register view working
path("account-inactive/", AccountInactiveView.as_view(), name="account_inactive"),
]
config/settings.py
ACCOUNT_AUTHENTICATION_METHOD = "email"
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_EMAIL_VERIFICATION = "mandatory"
ACCOUNT_USER_MODEL_USERNAME_FIELD = None
ACCOUNT_USERNAME_REQUIRED = False
访问寄存器视图后,没有错误。用户对象已创建且响应(代码 201)为:
{
"detail": "Verification e-mail sent."
}
但是没有发送电子邮件。
感谢您的帮助!
我解决了这个问题。出现此问题是因为 User
模型中 is_active
字段的默认值为 False
。并且出于某种原因 allauth
和 rest-auth
不允许为非活动用户发送激活电子邮件。
在我将用户模型更改为使用电子邮件而不是用户名后,当我访问 rest-auth.registration.views.RegisterView
时电子邮件没有发送。
我应该怎么做才能工作?
我的电子邮件设置是:
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
这是正确的配置,在 rest_auth.views.PasswordResetView
上发送电子邮件工作正常。
我的代码:
users/urls.py:
app_name = "users"
urlpatterns = [
path("register/", include("rest_auth.registration.urls")),
...
]
config/urls.py:
from allauth.account.views import AccountInactiveView
urlpatterns = [
...
path("api/v1/users/", include("myproject.users.urls")),
# this url is used to generate email content
# https://github.com/Tivix/django-rest-auth/blob/master/demo/demo/urls.py
path("password-reset/<uidb64>/<token>/", TemplateView.as_view(), name="password_reset_confirm")
# for some reason required for rest-auth register view working
path("account-inactive/", AccountInactiveView.as_view(), name="account_inactive"),
]
config/settings.py
ACCOUNT_AUTHENTICATION_METHOD = "email"
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_EMAIL_VERIFICATION = "mandatory"
ACCOUNT_USER_MODEL_USERNAME_FIELD = None
ACCOUNT_USERNAME_REQUIRED = False
访问寄存器视图后,没有错误。用户对象已创建且响应(代码 201)为:
{
"detail": "Verification e-mail sent."
}
但是没有发送电子邮件。
感谢您的帮助!
我解决了这个问题。出现此问题是因为 User
模型中 is_active
字段的默认值为 False
。并且出于某种原因 allauth
和 rest-auth
不允许为非活动用户发送激活电子邮件。