0

I am having this error: smtplib.SMTPAuthenticationError: (535, b'5.7.8 Username and Password not accepted. Learn more at\n5.7.8 https://support.google.com/mail/?p=BadCredentials ij28-20020a170902ab5c00b00163efcd50bdsm1197936plb.94 - gsmtp') when I try to send a gmail in my registration app

EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'repository0612@gmail.com'
EMAIL_HOST_PASSWORD = '****************'
EMAIL_PORT = 587

I read in some other related forums that you just have to turn on the less secure apps in your google account settings but google already disabled that particular setting. I also tried turning off the 2-way authentication and my EMAIL_HOST_USER and EMAIL_HOST_PASSWORD are as the same as my email and password. What else should I do to solve this problem?

kyo.cc
  • 1
  • 4
  • Is IMAP enabled in gmail? https://support.google.com/mail/answer/7126229?hl=en#zippy=%2Cstep-check-that-imap-is-turned-on Or go to this page (https://www.google.com/accounts/DisplayUnlockCaptcha) and then try again? – ldias Jun 05 '22 at 12:44

4 Answers4

1

This feature is no longer supported as of May 30th, 2022. See https://support.google.com/accounts/answer/6010255?hl=en&visit_id=637896899107643254-869975220&p=less-secure-apps&rd=1#zippy=%2Cuse-an-app-password

https://stackoverflow.com/a/27515833/19312416

Omar
  • 11
  • 1
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – STerliakov Jun 12 '22 at 09:22
1

So for new users we wont be able to use less secure app due to a new update, but there is nothing to worry.

In gmail after you allow 2 step authendication you will get a feature named app passsword you can use this.

Go to app password > provide name > copy password.

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_USE_TLS = True
EMAIL_PORT = 587
EMAIL_HOST_USER = 
EMAIL_HOST_PASSWORD = "paste that password"

this will work!

0

i believe your problem with code, try my function, it works with gmail, without additional settings

import smtplib
from email.mime.text import MIMEText


def email_sender(to_email, theme, message):
    sender = "example@gmail.com"
    password = "mypassword"
    body = message
    # make up message
    msg = MIMEText(body)
    msg['Subject'] = theme
    msg['From'] = sender
    msg['To'] = ", ".join(to_email)
    #sending
    session = smtplib.SMTP('smtp.gmail.com', 587)
    session.starttls()
    session.login(sender, password)
    send_it = session.sendmail(sender, to_email, msg.as_string())
    session.quit()
oruchkin
  • 1,145
  • 1
  • 10
  • 21
0

Thanks for the help guys. It already works by using the generated app password in my google account instead of using my own created password in EMAIL_HOST_PASSWORD

kyo.cc
  • 1
  • 4