Kupomix
Kupomix

Reputation: 13

SMTPSenderRefused (530, b'5.7.0 Authentication Required)

I make a website with django and im having some troubles whit the reset password feature in deployment with heroku (works fine locally), when i try to use it, an error pops up:

SMTPSenderRefused at /password-reset/ (530, b'5.7.0 Authentication Required. Learn more at\n5.7.0 https://support.google.com/mail/?p=WantAuthError a68sm8842573qkd.10 - gsmtp', 'webmaster@localhost') Request Method: POST Request URL: https://mytobiapp.herokuapp.com/password-reset/ Django Version: 3.0.4 Exception Type: SMTPSenderRefused Exception Value:
(530, b'5.7.0 Authentication Required. Learn more at\n5.7.0 https://support.google.com/mail/?p=WantAuthError a68sm8842573qkd.10 - gsmtp', 'webmaster@localhost') Exception Location: /app/.heroku/python/lib/python3.6/smtplib.py in sendmail, line 867 Python Executable: /app/.heroku/python/bin/python Python Version: 3.6.10 Python Path:
['/app/.heroku/python/bin', '/app', '/app/.heroku/python/lib/python36.zip', '/app/.heroku/python/lib/python3.6', '/app/.heroku/python/lib/python3.6/lib-dynload', '/app/.heroku/python/lib/python3.6/site-packages']

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("GMAIL")
EMAIL_HOST_PASSWORD = os.environ.get("CONTRASEÑA_GMAIL")

I already tried to allow acces to less secure apps and use the displayunlockcaptcha feature of google, but nothing seems to work. Any help will be apreciated

Upvotes: 1

Views: 3982

Answers (2)

Carewen
Carewen

Reputation: 173

I stumbled across this exact error recently when promoting a Django site into production.

Add the following into settings.py:

DEFAULT_FROM_EMAIL = '[email protected]'
SERVER_EMAIL = '[email protected]'

As soon as I added those into settings.py this error vanished.

Reference: Django deployment checklist

I would add that the above checklist is really worth reviewing. There are additional settings you should adjust in production, particularly concerning HTTPS.

Upvotes: 0

stocke777
stocke777

Reputation: 151

You probably haven't saved the environment variables properly. To test out if your variables are working then try this in that directory.

import os
a = os.environ.get('variable_a')
b = os.environ.get('variable_b')
print(a, b)

it should give None if not set.

Upvotes: 1

Related Questions