Search code examples
pythondjangoemailgmail

SMTP email error after Google's removal of less secure app access


Error:

SMTPAuthenticationError at /accounts/signup/
(535, b'5.7.8 Username and Password not accepted. Learn more at\n5.7.8  https://support.google.com/mail/?p=BadCredentials n1-20020a05620a294100b006a6b6638a59sm3664075qkp.53 - gsmtp')

Before the update, the email sender works. Now after the update the email sender has a STMP authentication error.

How can I fix this error?

Code:

EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = os.environ['mailbotPass']
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' 

Solution

  • You should look into generating an app password. The password generated can then be used in the place of the the actual password for that account.

    EMAIL_HOST = 'smtp.gmail.com'
    EMAIL_PORT = 587
    EMAIL_HOST_USER = '[email protected]'
    EMAIL_HOST_PASSWORD = os.environ['appsPassword']
    EMAIL_USE_TLS = True
    DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
    EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'