close

[Solved] smtplib.SMTPAuthenticationError: Username and Password not accepted

While I am trying to use SMTP I am facing the following error: smtplib.SMTPAuthenticationError: Username and Password not accepted in Python. We are going to Learn about All Possible Solutions So Lets Get Start with This Article.

How smtplib.SMTPAuthenticationError: Username and Password not accepted Error Occurs?

While I am trying to use SMTP I am facing following 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 c12-20020aa7d60c000000b0042be14040c1sm2612116edr.86 – gsmtp’)

So here I am writing all the possible solutions that I have tried to resolve this error.

How To Solve smtplib.SMTPAuthenticationError: Username and Password not accepted Error?

  1. How To Solve smtplib.SMTPAuthenticationError: Username and Password not accepted Error?

    To Solve smtplib.SMTPAuthenticationError: Username and Password not accepted Error You need to do Is Just Create App Password and then Use it and you'll be able to use SMTP. Just follow the below step to Create App Password. First of all Login into Your Gmail Account. And then Go To MyAccount Section By visiting https://myaccount.google.com Then Open Security Tab in the Sidebar As Shown in the Image. Then You can see There is Signing in to Google section and Make Sure you have turn on two steps verification if Not Then Turn On two steps verification. When You Turn On Your 2-Step Verification then you'll be able to see App Passwords option. And Now Click on App Passwords. Then select app as Mail and select your corresponding device. Then Click on Generate to create App Password. And You are Done. Now your app Password is been created and You are now able to Use this password in Your SMTP. Just Use this Password in SMTP And Now, Your error must be solved. Thank You.

  2. smtplib.SMTPAuthenticationError: Username and Password not accepted

    To Solve smtplib.SMTPAuthenticationError: Username and Password not accepted Error You need to do Is Just Create App Password and then Use it and you'll be able to use SMTP. Just follow the below step to Create App Password. First of all Login into Your Gmail Account. And then Go To MyAccount Section By visiting https://myaccount.google.com Then Open Security Tab in the Sidebar As Shown in the Image. Then You can see There is Signing in to Google section and Make Sure you have turn on two steps verification if Not Then Turn On two steps verification. When You Turn On Your 2-Step Verification then you'll be able to see App Passwords option. And Now Click on App Passwords. Then select app as Mail and select your corresponding device. Then Click on Generate to create App Password. And You are Done. Now your app Password is been created and You are now able to Use this password in Your SMTP. Just Use this Password in SMTP And Now, Your error must be solved. Thank You.

Solution 1: Create App Password

Google Has Already Announced that To help keep your account secure, starting May 30, 2022, Google will no longer support the use of third-party apps or devices that only ask for your username and password for you. sign in to your Google account.

So All You need to do Is Just Create App Password and then Use it and you’ll be able to use SMTP. Just follow the below step to Create App Password.

  • First of all Login into Your Gmail Account.
  • And then Go To MyAccount Section By visiting https://myaccount.google.com
  • Then Open Security Tab in the Sidebar As Shown in the Image.
  • Then You can see There is Signing in to Google section and Make Sure you have turn on two steps verification if Not Then Turn On two steps verification.
  • When You Turn On Your 2-Step Verification then you’ll be able to see App Passwords option.
  • And Now Click on App Passwords.
  • Then select app as Mail and select your corresponding device. Then Click on Generate to create App Password.
  • And You are Done. Now your app Password is been created and You are now able to Use this password in Your SMTP.
  • Just Use this Password in SMTP And Now, Your error must be solved. Thank You.

Solution 2: Use Just Like this

Once You have Completed Solution 1 All Step Then You Can Use Just Like This.

# your Gmail account 
import smtplib
  
# creates SMTP session
s = smtplib.SMTP('smtp.gmail.com', 587)
  
# start TLS for security
s.starttls()
  
# Authentication Your Email Address That You Used IN Solution 1
s.login("your_email_address", "your_app_password_that_you_created_above")
  
# message to be sent
message = "Message_you_need_to_send"
  
# sending the mail
s.sendmail("sender_email_id", "receiver_email_id", message)
  
# terminating the session
s.quit()

Conclusion

It’s all About this error. Hope We solved Your error. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you?

Also, Read

13 thoughts on “[Solved] smtplib.SMTPAuthenticationError: Username and Password not accepted”

  1. hey my bro thanks for all
    I could fix my trouble by your helpfull tutorial
    But one thing was more difficult at the end.
    where we should set generated code?
    After a lot of searchings I could find a way…
    So I want to talk one thing..
    if you add this section to this tutorial I believe that your tutorial will be 100% PERFECT and helpfull for every users however they are beginner level

    Reply

Leave a Comment