In order to use a Gmail account in an app, like a web app, you need to generate a password as described below. This is a 16 character password.
App Passwords required in Apps.
- Go to https://myaccount.google.com/security.
- Scroll down to "How you sign in to Google".
- Enable 2-Step Verification.
- Add App Password. You'll need to give it a name.
- Use the generated password in your code.
You can also use direct link https://myaccount.google.com/apppasswords