To generate app password to authenticate Gmail SMTP when two-factor authentication is enabled.
1. Login to your Gmail account and visit https://myaccount.google.com/
2. Click on “Signing in to Google” from Sign-in & Security section. Google will ask for entering the password again, enter the password and sign in again.
3. Click on App passwords as shown in below image. It will show the list of previously create app passwords.
4. Update the following details as shown in below image.
Select app: Mail
Select Device: Other (custom name)
5. Enter the name which you want to update (this is just for your future reference).
6. Click on the Generate button.
7. App password is generated now. Note it down somewhere else.
If you forgot this app password then you can not reset it and need to generate it again.