Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Login Authentication failed with Gmail SMTP (Updated)

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("[email protected]", "your_password")
message = "TEST"

server.sendmail("[email protected]", "[email protected]", message)
server.quit()
like image 334
Alan Shiah Avatar asked Oct 29 '25 22:10

Alan Shiah


1 Answers

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:

  1. Go into your sending email address and make your way to the settings.
  2. Find two-step authentication and enable it.
  3. Under two-step authentication there should be a tab labeled App passwords. Click on it then select mail as the app and your device of choice
  4. Use the password generated from the app password as the password for your Gmail account.

Credits to: Link to source

like image 148
Alan Shiah Avatar answered Oct 31 '25 12:10

Alan Shiah



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!