I know this question has been asked many a times before. But the solutions didn\'t seem to help me . So hereby I am posting my code:
If you’re sure your password is correct, you can try these troubleshooting tips:
- If you've turned on 2-Step Verification for your account, you might need to enter an App password.
- Sign in to your account from the web version of Gmail at https://mail.google.com. Afterwards try accessing your messages in your mail app again.
- If you're still having problems, visit http://www.google.com/accounts/DisplayUnlockCaptcha and sign in with your Gmail username and password. If necessary, enter the letters in the distorted picture.
- Your mail app might not support the latest security standards. Learn how to allow less secure apps access to your account.
- Make sure your mail app isn't set to check for new email too frequently. If your mail app checks for new messages more than once every 10 minutes, the app’s access to your account could be blocked.
- Try changing your password according to our tips on creating a strong password.
Source.
Here, you can allow less secure apps. Click on Turn On to allow less secure apps having your username and password.
If you are facing similar issue
Try this out:
If you had your password last modified before 2014 change your password to stronger one.
It worked for me