用Django注册发送激活电子邮件

2024-04-24 03:24:37 发布

您现在位置:Python中文网/ 问答频道 /正文


Tags: python
3条回答

EMAIL_PORT=465一年前还在工作。现在你需要在gmail上使用587端口。 原因:Django从一开始就不支持带有SSL的SMTP。设置纯文本连接后,仅支持STARTTLS命令。然而,Gmail不再支持465端口上的这个选项。

希望这对某人有帮助。经过半个小时的故障排除,我意识到我必须在使用django注册时明确声明这一点-

电子邮件后端='django.core.mail.backends.smtp.EMAIL BACKEND'

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

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

如果要工作,则必须在settings.py中指定DEFAULT_FROM_EMAIL的值。

另外,请注意以下几点:

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.

因此,举个例子,我在settings.py文件中使用了以下内容来使用gmail帐户:

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

EMAIL_HOST_USER = 'my@gmail.com'
EMAIL_HOST_PASSWORD = 'my_emails_password'

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

相关问题 更多 >