0

Django sendmail is not working, I'm getting this error:

(535, b'5.7.8 Username and Password not accepted. Learn more at\n5.7.8 https://support.google.com/mail/?p=BadCredentials q13sm252028qtx.80 - gsmtp')

There are similar question on S.O.,like this. everyone taking about "allow less secure apps", but I already turn that option ON. My auth details are correct, I had tried with two different accounts. Two step verification is disabled.

settings.py

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'myemail'
EMAIL_HOST_PASSWORD = 'mypassword'
EMAIL_USE_TLS = True

views.py

def sendmail(email,token):
    subject = 'Verify Email'
    message = 'Hello User please activate your account by click on this link '+'http://mywebsite.pythonanywhere.com/email/verify/'+token
    from_email = 'praveexxxxxxxxxxx@gmail.com'
    recipient_list = [email]
    send_mail(subject=subject,message=message,from_email=from_email,recipient_list=recipient_list)

def signup(request):
    token = generatedtoken
    email = someoneemail@gmail.com
    sendmail(email,token)
marc_s
  • 704,970
  • 168
  • 1,303
  • 1,425
Praveen Yadav
  • 413
  • 4
  • 16
  • 2
    Take a look at app-specific passwords https://help.pythonanywhere.com/pages/GmailAppSpecificPasswords – Filip Oct 27 '21 at 09:41
  • Did you try logging in from a browser using same authentication credentials?, Try logging in from an incognito window. – Ruby Dec 08 '21 at 18:39

1 Answers1

0

This error shows that you login creds were incorrect, if you are sure that the SMTP authentication creds you provided were correct, you may need to set up Gmail App Specific Password as it make your authentication with google easier and more secured.

I some cases, Gmail App Specific Password may not be available in your region, an alternative is Accepting Login From Less Secure App.

Ruby
  • 83
  • 1
  • 1
  • 9