you need to convert to oauth authentication:
https://developers.google.com/gmail/imap/xoauth2-protocol
you may want to use a clientid
https://developers.google.com/identity/gsi/web/guides/get-google-api-clientid
if it is a program with a UI you may want to host a web view for login to get the token. you can also use httpclient post the form and host web server port for the authentication server to redirect back to. (register localhost:<port> as a valid reply url).
if the application does not have a UI, you will want a separate program with a UI that saves the refresh token somewhere the app can access. The token will expire and need to be updated periodically.