Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SMTP Authentication Error with Django on Heroku

I am trying to send emails from my django app using the the gmail smtp servers. The emails are being sent when I run the application on my local server. But I'm getting an SMTP Authentication Error while using it on heroku.

Traceback - link

settings.py -

# Email configuration.

EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = '***************@gmail.com'
EMAIL_HOST_PASSWORD = '************'
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = '******************@gmail.com'
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'

And I have rechecked the account password, also I have enabled the access of less secure apps from my google account. But still I am getting this error.

like image 755
Anurag-Sharma Avatar asked Sep 03 '17 05:09

Anurag-Sharma


2 Answers

Disabling CAPTCHA for clients
If you are not using 2-factor authentication and you have verified the credentials in your Python source are correct, follow these steps:

  1. Login to gmail in your browser
  2. Navigate to the DisplayUnclockCaptcha page.
  3. Click the continue button, and you will see the message
    Account access enabled Please try signing in to your Google account again from your new device or application.

  4. Run your Python script - your login attempt should be successful.

like image 188
Sergey Avatar answered Sep 24 '22 02:09

Sergey


Try using sendgrid, because gmail smtp has some problem. I too was unable to do using gmail smtp. But it worked perfectly using sendgrid. And this is also free for basic use.

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.sendgrid.net'
EMAIL_HOST_USER = 'username'
EMAIL_HOST_PASSWORD = 'userpassword'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = '[email protected]'
like image 39
Astik Anand Avatar answered Sep 23 '22 02:09

Astik Anand