如何配置 Cookiecutter Django 以使用 Gmail SMTP

How to configure Cookiecutter Django to use Gmail SMTP

任何人都可以帮助我配置我的 django cookiecutter 生产设置以使用 Gmail SMTP。

我已经使用 docker 部署了我的应用程序。 Cookiecutter 让您可以将您的应用程序配置为任何邮件提供商。我选择了 Mailgun,但是我没有经过域名提供商验证的电子邮件地址。所以,我无法在我的应用程序中注册任何用户,因为(https://cookiecutter-django.readthedocs.io/en/latest/deployment-with-docker.html#configuring-the-stack)这里说你不能:)

我已尝试将默认电子邮件验证设置从 "mandatory" 覆盖为 "none"。然而,它仍然抛出 500。在下面,我添加了所有授权设置。 我不得不决定要么购买一个电子邮件地址,要么配置我的应用程序以使用 Gmail Smtp,或者摆脱这个电子邮件验证过程。

settings/base.py

ACCOUNT_ALLOW_REGISTRATION = env.bool("DJANGO_ACCOUNT_ALLOW_REGISTRATION", True)
# https://django-allauth.readthedocs.io/en/latest/configuration.html
ACCOUNT_AUTHENTICATION_METHOD = "username"
# https://django-allauth.readthedocs.io/en/latest/configuration.html
ACCOUNT_EMAIL_REQUIRED = True
# https://django-allauth.readthedocs.io/en/latest/configuration.html
ACCOUNT_EMAIL_VERIFICATION = "none"



# https://docs.djangoproject.com/en/dev/ref/settings/#email-backend
EMAIL_BACKEND = env(
    "DJANGO_EMAIL_BACKEND", default="django.core.mail.backends.smtp.EmailBackend"
)

任何摆脱这 500 的方法都很棒。

您没有配置电子邮件主机和来自发件人的电子邮件。试试这个

EMAIL_BACKEND = env(
    "DJANGO_EMAIL_BACKEND", default="django.core.mail.backends.smtp.EmailBackend"
)
EMAIL_HOST = "smtp.gmail.com"
EMAIL_PORT = 587
EMAIL_HOST_USER = "your_email@gmail.com"
EMAIL_HOST_PASSWORD = "email_password"
DEFAULT_FROM_EMAIL = "email_of_sender@gmail.com" # same with EMAIL_HOST_USER
EMAIL_USE_TLS = True
EMAIL_USE_SSL = False
# https://docs.djangoproject.com/en/dev/ref/settings/#email-timeout
EMAIL_TIMEOUT = None