I am using my Gmail account and smtp.gmail.com
inside my web application to test and send email. when two factor authentication is ON for my Gmail account, it fails to send the email, however when I turn it off, the web application sends email successfully. Appreciate any kind of advice.
Create a custom app in you Gmail security settings.
Use the token as password in combination with your full Gmail account and two factor authentication will not be required.
Note: The link in step 2 will work only if you have 2-factor-authentication enabled.