使用 django-registration 发送激活电子邮件

发布于 2024-09-02 15:29:25 字数 77 浏览 5 评论 0原文

我很好奇是否有办法使用 django-registration 发送带有用户名和密码的激活电子邮件。首先我考虑修改注册表,但我需要一些例子。

I am curious if there's a way to send activated email with username, password by using django-registration. First I thought about modifying registration form but I need some example.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

好倦 2024-09-09 15:29:25

django-registration 在内部使用以下代码来处理发送电子邮件:

send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [self.user.email])

如果您想工作,您必须在 settings.py 中指定值 DEFAULT_FROM_EMAIL。

另请注意以下事项:

邮件是使用 SMTP 主机发送的,并且
EMAIL_HOST 中指定的端口和
EMAIL_PORT 设置。这
EMAIL_HOST_USER 和
EMAIL_HOST_PASSWORD 设置(如果设置)
用于对 SMTP 进行身份验证
服务器和 EMAIL_USE_TLS 设置
控制是否安全连接
已使用。

因此,举个例子,这是我在 settings.py 文件中使用的 gmail 帐户:

EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 465
EMAIL_USE_TLS = True

EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'my_emails_password'

django-registration 应该能够发送电子邮件。

django-registration uses the following code, internally, to handle sending emails:

send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [self.user.email])

If you want to work, you will have to specify the value DEFAULT_FROM_EMAIL in your settings.py.

Also, note the following:

Mail is sent using the SMTP host and
port specified in the EMAIL_HOST and
EMAIL_PORT settings. The
EMAIL_HOST_USER and
EMAIL_HOST_PASSWORD settings, if set,
are used to authenticate to the SMTP
server, and the EMAIL_USE_TLS setting
controls whether a secure connection
is used.

So, to give an example, here's what I've used in a settings.py file to use a gmail account:

EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 465
EMAIL_USE_TLS = True

EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'my_emails_password'

django-registration should then be able to send emails.

空城仅有旧梦在 2024-09-09 15:29:25

EMAIL_PORT = 465 一年前可用。现在您需要将端口 587 用于 gmail。
原因:Django从一开始就不支持带有SSL的SMTP。建立纯文本连接后仅支持 STARTTLS 命令。但是,Gmail 在端口 465 上不再支持此选项。

EMAIL_PORT = 465 was working some year ago. Now you need to use port 587 with gmail.
Reason: Django does not support SMTP with SSL from the beginning. Only STARTTLS command is supported AFTER plain-text connection is set up. Gmail, however, no longer supports this option on port 465.

梦中的蝴蝶 2024-09-09 15:29:25

希望这会对某人有所帮助。 时也必须明确声明这一点

经过半个小时的故障排除后,我意识到在使用 django-registration - EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'

Hope this will help someone. After troubleshooting for half an hour, I realised that I had to explicitly state this as well while using django-registration -

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'

坚持沉默 2024-09-09 15:29:25

django-register-activate 实现了与 django-registration 类似的功能。基本上它提供了用户注册、电子邮件验证和激活、用户登录和用户注销的代码。

如果您需要示例来实现自己的代码,您可以检查 register_activate 以获得一些提示。

希望答案有帮助。如果您还有其他问题,请告诉我。

django-register-activate implemented a similar functionality as django-registration. Basically it provides code for user sign up, email verification and activation, user login and user logout.

If you need examples to implement your own code, you may check the views.py and forms.py in register_activate to get some hints.

Hope the answer helps. Let me know if you have further questions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文