When trying to login into a Gmail account using SMTP, this error message occurs:
SMTPAuthenticationError(code, resp)
smtplib.SMTPAuthenticationError: (535, b'5.7.8 Username and Password not accepted.
Code causing the error:
import smtplib
server = smtplib.SMTP("smtp.gmail.com", 587)
server.starttls()
server.login("sending@gmail.com", "your_password")
message = "TEST"
server.sendmail("sending@gmail.com", "receiving@gmail.com", message)
server.quit()
Google has disabled the ability to enable less secure apps as of May 2022. Because of this, the previous solution of enabling less secure apps is no longer valid.
Steps:
Credits to: Link to source