0

I am developing a web-app in Django that needs to send automated emails. The username and password are saved locally in my Windows 10 environment variables. The app is able to send emails locally, but in proudction once deployed to Heroku, the following error is raised:

530, b'5.7.0 Authentication Required. Learn more at\n5.7.0  https://support.google.com/mail/?p=WantAuthError y7sm6660123qtn.11 - gsmtp', 'webmaster@localhost'

My guess is that the environment variables are not being accessed which is why this error is thrown.

Here is my code in settings.py

EMAIL_HOST = 'smtp.gmail.com'
EMAIL_USE_TLS = True
EMAIL_PORT = 587
EMAIL_HOST_USER = os.environ.get('NAHE-USER')
EMAIL_HOST_PASSWORD = os.environ.get('NAHE-PASS')
Osaama Shehzad
  • 147
  • 1
  • 2
  • 12

1 Answers1

0

You can define the environment variables (NAHE-USER, NAHE-PASS) in Heroku using Config Vars.
There are injected at runtime and will be accessed by your code with os.environ.get('NAHE-USER')

Beppe C
  • 11,256
  • 2
  • 19
  • 41
  • Hi! I defined the environment variables in the Heroku settings. Created an ```.env``` file and a ```.gitignore``` file. It was able to send messages locally, but again, gave error in production when deployed to Heroku. This is the error I got: ```smtplib.SMTPAuthenticationError: (534, b'5.7.14 – Osaama Shehzad Sep 20 '20 at 12:25
  • It looks like a different problem, it appears you can get the env variables but the access is somehow rejected by Google. Does this help? https://stackoverflow.com/questions/26852128/smtpauthenticationerror-when-sending-mail-using-gmail-and-python – Beppe C Sep 20 '20 at 12:32
  • Thanks so much! It appears that Google was rejecting the sign-in. – Osaama Shehzad Sep 20 '20 at 12:36
  • I have had the same experience with Yahoo, I had to lower/disable some security layers – Beppe C Sep 20 '20 at 13:53