Generate an App Password:
1. Go to Google Account Security Settings.
2. Under "Signing in to Google," find App passwords and create one for this script (you’ll need to have 2-step verification enabled on your account).
3. Use this app password in the script instead of your Gmail account password.