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?
- 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.
- 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
- Error: You need to specify a command before moving on. Use ‘–help’ to view the available commands
- Loading PostCSS “postcss-preset-env” plugin failed: Cannot find module ‘node:vm’
- WARNING: There was an error checking the latest version of pip
- npm WARN config global `–global`, `–local` are deprecated. Use `–location=global` instead
- TypeError: Descriptors cannot not be created directly
thank you so much ,your steps help me
It’s my Pleasure to Help You Brother. Thank You For Your Valuable words.
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
Thank You Mirolim. As Per Your Suggestion, we Have Updated Our Solution With Code. Thank You Again For Your Valuable Suggestion.
Thank you so much, it helped!
It’s my Pleasure to Help You Joe. Thank You For Your Valuable words.
Thank you a lot, super useful!
It’s my Pleasure to Help You Babacar. Thank You So Much For Your Valuable words.
Great, man. U helped me a lot 🙂
It’s my Pleasure to Help You Roberto Luna. Thank You So Much For Your Valuable words.
thank you so much bro! Solution-1 saved my life 🙂
It’s my Pleasure to Help You Aydin. Thank You So Much For Your Valuable words.
hey thank you it worked out for me.