[英]Django registration email not sending
我一直在嘗試將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設置錯誤!
任何見解都非常感謝!
編輯:當嘗試'重置密碼'電子郵件功能時,我收到此錯誤
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
您可能想嘗試添加DEFAULT_FROM_EMAIL
設置並設置以下設置:
EMAIL_USE_TLS = True
EMAIL_USE_SSL = True
這將允許Django使用安全的電子郵件發送。
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
可在此處找到有關密碼的更多幫助
檢查你的urls.py文件,並確保你使用的是hmac而不是簡單的
urlpatterns = [
#...
url(r'^accounts/', include('registration.backends.hmac.urls')),
]
另外,在你的setting.py,INSTALLED_APPS中,確保'registration'在django.contrib.auth之前。
INSTALLED_APPS = [
#.....
'registration',
'django.contrib.auth',
#...
]
我知道這是一個老問題,但我認為這有助於其他人尋找答案。 您已設置urlconf以使用一步注冊。 以下是他們的文檔片段 -
這個后端的工作流程盡可能簡單:
如果要在控制台中查看電子郵件,請使用以下urlconf -
url(r'^account/', include('registration.backends.default.urls')),
希望有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.