Django registration email not sending

无人久伴 提交于 2020-01-01 10:28:07

问题


I've been trying to get the django-registration-redux account activation email to send to newly registered users.

I've gotten all non-email related parts to work, such as loggin in/out and actually registering the user! When i register, it automatically logs my in as that user. But i never get the activation email.

I've tried various different things to try get this to work, I've followed some tutorials on setting whole thing up but the emails still dont work.

heres some of the code setup, im using registration templates that i downloaded online.

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

am i missing any important settings here?

urls.py

# included amongst my other urls
(r'^accounts/', include('registration.backends.simple.urls')),

seems all in order with the tutorials and documentation. like i said, registration works perfectly bar the emails.

one thing ive noticed is that you probably shouldn't have auto loggin = True if you want a user to activate their accounts, but commenting that line out didnt change anything, i still got logged in automatically after registering. Seems like a minor aside but maybe this has something to do with the emails not working?

i dunno, im lost with it. Either im missing some settings, the code doesnt work, python smtpd doesnt work, or my smtp.live.com settings are wrong!

any insigths greatly appreciated!

EDIT: when trying the 'reset password' email function i get this error

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

EDIT 2: using these settings i get the the password/reset/done page but recieve no actual email

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

EMAIL_HOST = '127.0.0.1'
EMAIL_PORT = 1025

回答1:


You may want to try adding a DEFAULT_FROM_EMAIL setting and setting these settings:

EMAIL_USE_TLS = True
EMAIL_USE_SSL = True

This will allow Django to use secure email-sending.




回答2:


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

will only display the email on the console.

Instead you should use

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

Moreover it is more convenient to use a existing smtp server like gmail

For that you need to add these to your django settings file

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

More help on the password can be found here




回答3:


Check your urls.py file, and make sure you are using the hmac not the simple

urlpatterns = [
    #...    
    url(r'^accounts/', include('registration.backends.hmac.urls')),
]

Also, in your setting.py, INSTALLED_APPS, make sure that the 'registration' is before django.contrib.auth.

INSTALLED_APPS = [
    #.....
    'registration',
    'django.contrib.auth',
    #...
]



回答4:


I know this is an old question, but I thought it would help anybody else looking for the answer. You have setup your urlconf to use the one step registration. Below is a snippet from their docs -

This backend’s workflow is deliberately as simple as possible:

  1. A user signs up by filling out a registration form.
  2. The user’s account is created and is active immediately, with no intermediate confirmation or activation step.
  3. The new user is logged in immediately.

If you want to see the emails in the console, use the following urlconf instead -

url(r'^account/', include('registration.backends.default.urls')),

Hope that helps.



来源:https://stackoverflow.com/questions/29615858/django-registration-email-not-sending

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!