Don't forget to generate a second password for your Gmail account. You will use this new password in your code. Read this:
https://support.google.com/accounts/answer/185833
Under the section "How to generate an App password" click on "App passwords", then under "Select app" choose "Mail", select your device and click "Generate". Your second password will be printed on the screen.