Django:重置密码不发送电子邮件 [英] Django: reset-password not sending email

查看:125
本文介绍了Django:重置密码不发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Django密码重置。



我的 settings.py 中有以下代码:

  EMAIL_USE_TLS =真
EMAIL_HOST ='smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER ='myusername @ gmail .com'
EMAIL_HOST_PASSWORD ='mypassword'
DEFAULT_FROM_EMAIL ='myusername@gmail.com'
EMAIL_BACKEND ='django.core.mail.backends.smtp.EmailBackend'
SERVER_EMAIL = 'myusername@gmail.com'

它将我重定向到正确的页面,但没有发送电子邮件。我已经检查了Spam文件夹等等,但还是没什么:(



任何想法都很感激!



编辑



我尝试使用控制台对其进行测试,但出现以下错误:

 >>> email = EmailMessage('Mail test','this is a test',to = ['myusername@gmail.com'])
>>> email.send()

追溯(最近一次通话):
文件<控制台>,< module> $ b中的第1行$ b文件 /usr/local/lib/python2.7/dist-packages/django/core/mail/message.py,行255,在发送
中返回self.get_connection(fail_silently).send_messages([自我])
文件 /usr/local/lib/python2.7/dist-packages/django/core/mail/backends/smtp.py,第88行,位于send_messages
new_conn_created = self中。 open()
文件 /usr/local/lib/python2.7/dist-packages/django/core/mail/backends/smtp.py,第55行,在打开的
self.connection中。 login(self.username,self.password)
文件 / usr / lib / python2 .7 / smtplib.py,第576行,登录时
引发SMTPException(服务器不支持SMTP AUTH扩展名。)

SMTPException:服务器不支持SMTP AUTH扩展名。

编辑



我已经按照上述配置了settings.py。由于某种原因,它以前不起作用,但现在似乎可以了。当我运行

  python manage.py shell 

并使用EmailMessage和send()函数对其进行测试,我得到的状态码为1,并且收到电子邮件。但是,我仍然没有从password_reset获得电子邮件。有任何想法吗?谢谢大家的输入!

解决方案

在Django shell中进行发送测试时,这意味着您的电子邮件设置已正确配置。 / p>

如果仍然没有从 password_reset 接收电子邮件,则必须在此字段中搜索问题。



您必须知道密码重置电子邮件仅发送给活动用户( is_active ),并且只有他们具有可用密码( has_usable_password )时。



如果用户输入的密码无效,Django会静静地不发送重置电子邮件。



在Django Shell中使用以下代码测试所有用户:

 来自django.contrib.auth import get_user_model 

[(u.email,u.is_active,u.has_usable_password())for u in get_user_model()。objects.all()]


I am using the Django password reset.

I have this code in my settings.py:

EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'myusername@gmail.com'
EMAIL_HOST_PASSWORD = 'mypassword'
DEFAULT_FROM_EMAIL = 'myusername@gmail.com'
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
SERVER_EMAIL = 'myusername@gmail.com'

It redirects me to the right page, but it doesn't send the email. I have checked the Spam folder and such, but still nothing :(

Any ideas are much appreciated!

Edit

I have tried to test it using the console but I get the following error:

>>> email = EmailMessage('Mail test', 'this is a test', to=['myusername@gmail.com'])
>>> email.send()

Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/django/core/mail/message.py", line 255, in send
return self.get_connection(fail_silently).send_messages([self])
File "/usr/local/lib/python2.7/dist-packages/django/core/mail/backends/smtp.py", line 88, in send_messages
new_conn_created = self.open()
File "/usr/local/lib/python2.7/dist-packages/django/core/mail/backends/smtp.py", line 55, in open
self.connection.login(self.username, self.password)
File "/usr/lib/python2.7/smtplib.py", line 576, in login
raise SMTPException("SMTP AUTH extension not supported by server.")

SMTPException: SMTP AUTH extension not supported by server.

Edit

I have the settings.py configured as above. For some reason it wasn't working before, but now it seems to be. When I run

python manage.py shell

and test it using the EmailMessage and send() function, I get a status code of 1, and I receive the email. However, I am still not getting the email from the password_reset. Any ideas? Thanks everyone for your input!

解决方案

As your sending test in Django shell works it means that your email settings are well configured.

If you still not getting the email from the password_reset you have to search your problem in this field.

You have to know that the password reset email is sent only to active users (is_active), and only if they have an usable password (has_usable_password).

If an user has an invalid password, Django will just silently not send the reset email.

Use the following code in the Django shell to test all your users:

from django.contrib.auth import get_user_model

[(u.email, u.is_active, u.has_usable_password()) for u in get_user_model().objects.all()]

这篇关于Django:重置密码不发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆