Some persons enable two factor authentication in gmail for security. In such cases we could not use that mail id in smtp mailer by default.
This article explains the details to use gmail with two factor authentication in smtp mailer.
Step1: Log-in into Gmail account that we need to use in smtp mailer.
Step2: Navigate to https://security.google.com/settings/security/apppasswords.
Step3: In 'select app' choose 'custom', give it an arbitrary name and press generate.
Step4: It will give you 16 chars token.
Step5: Use the token as password in combination with full Gmail account name and two factor authentication will not be required.