python-3.x - 如何配置 Cookiecutter Django 以使用 Gmail SMTP
问题描述
谁能帮我配置我的 django cookiecutter 生产设置以使用 Gmail SMTP。
我已经使用 docker 部署了我的应用程序。Cookiecutter 让您可以将您的应用程序配置为任何邮件提供商。我选择了 Mailgun,但是我没有经过我的域提供商验证的电子邮件地址。所以,我无法将任何用户注册到我的应用程序,因为(https://cookiecutter-django.readthedocs.io/en/latest/deployment-with-docker.html#configuring-the-stack)这里说你可以'吨:)
我试图将默认电子邮件验证设置从“强制”更改为“无”。但是,它仍然抛出了 500。在下面,我添加了 all-auth 设置。我必须决定要么购买一个电子邮件地址,要么配置我的应用程序以使用 Gmail Smtp,或者摆脱这个电子邮件验证过程。
设置/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
推荐阅读
- r - 分配给包含在观察表达式中的对象的值在输入或输出 IF 时给了我不同的值
- javascript - 将下拉值传递给 Index ActionResult 参数以刷新我的视图数据
- ios - 无法在模态呈现的视图上使用关闭
- java - @JsonInclude(Include.NON_EMPTY) 在使用 CUSTOM SERIALIZER 时不起作用
- php - 用链接查找和替换关键字,但忽略 div 内容
- visual-studio - mvtnorm 无法在 MS r-client 版本 3.4.3 中加载
- asp.net - 如何使用 signalR 将我的网络摄像头流式传输给网站上的用户
- amazon-web-services - 尝试使用 LetsEncrypt 安装 SSL 证书
- database - 两个 PostgreSQL 模式之间的差异以更新脚本
- go - 如何使用 godoc 和 go 模块提供文档?