Starting February 15, 2021, G Suite accounts will only allow access to apps using OAuth. Password-based access will no longer be supported.

You will need to create an App Password to use with your IMAP connection, instead of using your normal login details.

To continue using a specific app with your G Suite accounts, users in your organization must switch to a more secure type of access called OAuth. This connection method allows apps to access accounts with a digital key instead of requiring a user to reveal their username and password. We recommend that you share the user instructions (included below) with individuals in your organization to help them make the necessary changes. Alternatively, if your organization is using custom tools, you can ask the developer of the tool to update it to use OAuth. Developer instructions are also included below.

Please see here for more info, where you can add an App Password, which is effective also if you are using two factor authentication and require a second method to connect:

https://support.google.com/accounts/answer/185833