Go to your Google Account settings at myaccount.google.com.
Navigate to the "Security" section.
Once 2-Step Verification is active, locate the "App Passwords" option.
Generate a new App Password by selecting the application and device type.
Use the generated 16-character password in place of your Gmail password for SMTP authentication.