If SMTP or IMAP access to your Gmail account no longer works with your username and password, you may need to enable it in Gmail settings.
By default, Gmail considers username/password authentication not secure enough and allows only OAuth 2.0 authentication for SMTP and IMAP. If migrating to OAuth 2.0 in your application is not an option, you can use Allowing less secure apps to access your account to enable username/password authentication again.
In addition to the above, you may also need to log in Gmail web interface every time your account is accessed via SMTP or IMAP from a new IP address. This is to confirm that the sign in attempt from a new location was initiated by you.
However, if you’re OK with OAuth 2.0 way suggested by Google, you can check MailBee.NET OAuth 2.0 tutorials on how to upgrade your installed (desktop/console) or web applications to OAuth 2.0 security.