Reputation: 1927
I am new in Django. I am trying to add a feature in my project that enables user to reset his password through given email. These configurations are in development and not production. This is my configuration in settings.py
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = os.environ.get('EMAIL_USER')
EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_PASS')
I tried these but nothing seems to be working. I enabled IMAP from gmail settings as well. Can you please help me what am I doing wrong in here! In case if you want to see full error.
SMTPAuthenticationError at /password-reset/ (535, b'5.7.8 Username and Password not accepted.
https://support.google.com/mail/?p=BadCredentials a24sm3958276ljd.32 - gsmtp')
URL: http://localhost:8000/password-reset/ Exception Type: SMTPAuthenticationError b'5.7.8 Username and Password not accepted. Learn more at\n5.7.8 https://support.google.com/mail/?p=BadCredentials a24sm3958276ljd.32 - gsmtp') Exception Location: C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\smtplib.py in auth, line 642 Python Executable: C:\Users\Administrator\AppData\Local\Programs\Python\Python37\python.exe Python Version: 3.7.2 Python Path:
['C:\Users\Administrator\Desktop\django_project', 'C:\Users\Administrator\AppData\Local\Programs\Python\Python37\python37.zip', 'C:\Users\Administrator\AppData\Local\Programs\Python\Python37\DLLs', 'C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib', 'C:\Users\Administrator\AppData\Local\Programs\Python\Python37', 'C:\Users\Administrator\AppData\Roaming\Python\Python37\site-packages', 'C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages'] Server time: Thu, 4 Apr 2019 12:24:22 +0000Learn more at\n5.7.8Request Method: POST RequestDjango Version: 2.1.7Exception Value: (535,
Upvotes: 3
Views: 10869
Reputation: 1
Make sure that your os.environ.get('EMAIL_USER')
refers to your 'mail address' and not the name you set for your app password on your account setting!
Upvotes: 0
Reputation: 1
You need to do 2 things to get over very strong google's security.
Allow less secure apps: ON ↓↓↓
Allow access to your Google account: ON (Tap "Continue") ↓↓↓
Upvotes: 1
Reputation: 755
In my case it was working on my local machine but not on heroku server. I went on this link https://accounts.google.com/DisplayUnlockCaptcha and clicked on Continue. After that I had to re-login into my gmail account. It started working. Hope it might help someone!
Upvotes: 4
Reputation: 251
Would you mind double checking if your environment variables are set correctly? Also, did you enable this feature on your Google account: https://www.google.com/settings/security/lesssecureapps?
Take a look at this answer, as it might help you as well: SMTPAuthenticationError when sending mail using gmail and python
Upvotes: 4