我一直试图将django-registration-redux帐户激活电子邮件发送给新注册的用户。
我已经使所有与电子邮件无关的部分工作,例如登录/注销和实际注册用户!当我注册时,它会自动以该用户身份登录。但我从来没有收到激活邮件。
我尝试了各种不同的方法来尝试让它发挥作用,我已经按照一些关于设置整个事情的教程,但电子邮件仍然无效。
继承了一些代码设置,即使用我在线下载的注册模板。
settings.py
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'registration',
'synths',
)
# user reg settings
REGISTRATION_OPEN = True
ACCOUNT_ACTIVATION_DAYS = 7
REGISTRATION_AUTO_LOGIN = True
LOGIN_REDIRECT_URL = '/'
LOGIN_URL = '/login/'
# i tried including this line but still nothing
# EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
# email
# first i tried setting up the debbuging server with this CMD line
# python -m smtpd -n -c DebuggingServer localhost:1025
# i dont know if it worked!, i got no errors but the cursor just
# sat there blinking at me! i was expecting some output to tell me
# the server had started
# these were the settings i used for that
EMAIL_HOST = '127.0.0.1'
EMAIL_PORT = 1025
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''
# then i tried using my own address and smtp.live.com
EMAIL_HOST = 'smtp.live.com'
EMAIL_PORT = 25
EMAIL_HOST_USER = 'myemailaddress@hotmail.com'
EMAIL_HOST_PASSWORD = '123123abcabc'
# still nothing
我在这里错过了任何重要的设置吗?
urls.py
# included amongst my other urls
(r'^accounts/', include('registration.backends.simple.urls')),
似乎与教程和文档一致。就像我说的,注册工作完全禁止电子邮件。
我注意到的一件事是你可能不应该有自动loggin = True如果你想要一个用户激活他们的帐户,但评论该行没有改变任何东西,我仍然在注册后自动登录。看起来像是一个小问题,但也许这与电子邮件不起作用有关?
我不知道,我迷失了。要么我缺少一些设置,代码不起作用,python smtpd不起作用,或者我的smtp.live.com设置错误!
任何人都非常感谢!
编辑:尝试重置密码时#39;电子邮件功能我收到此错误
SMTPException at /accounts/password/reset/
SMTP AUTH extension not supported by server.
Request Method: POST
Request URL: http://localhost:8000/accounts/password/reset/
Django Version: 1.7.6
Exception Type: SMTPException
Exception Value: SMTP AUTH extension not supported by server.
Exception Location: C:\Python34\lib\smtplib.py in login, line 613
Python Executable: C:\Python34\python.exe
Python Version: 3.4.3
编辑2:使用这些设置我得到密码/重置/完成页面但没有收到实际的电子邮件
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
EMAIL_HOST = '127.0.0.1'
EMAIL_PORT = 1025
答案 0 :(得分:2)
您可以尝试添加anonymousListener
设置并设置这些设置:
DEFAULT_FROM_EMAIL
这将允许Django使用安全的电子邮件发送。
答案 1 :(得分:1)
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
只会在控制台上显示电子邮件。
相反,你应该使用
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
此外,使用像gmail这样的现有smtp服务器更方便
为此您需要将这些添加到您的django设置文件
EMAIL_BACKEND='django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST ='smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'youruser@gmail.com'
EMAIL_HOST_PASSWORD = 'gmail app password' #This is not your gmail password.
EMAIL_USE_TLS = True
可以找到有关密码的更多帮助here
答案 2 :(得分:1)
检查 urls.py 文件,确保使用 hmac 而不是简单
urlpatterns = [
#...
url(r'^accounts/', include('registration.backends.hmac.urls')),
]
另外,在你的setting.py,INSTALLED_APPS中,请确保注册'在django.contrib.auth之前。
INSTALLED_APPS = [
#.....
'registration',
'django.contrib.auth',
#...
]
答案 3 :(得分:0)
我知道这是一个老问题,但我认为这会有助于其他人寻找答案。您已设置urlconf以使用一步注册。以下是docs -
的摘录这个后端的工作流程尽可能简单:
如果您想在控制台中查看电子邮件,请使用以下urlconf -
url(r'^account/', include('registration.backends.default.urls')),
希望有所帮助。