This error will occur when the user you are trying to connect through IMAP have disabled access to "Less secure applications" or if IMAP is not enabled.
First, check whether IMAP is active for the email account. If not, log into the email account and enable it (follow the steps in this documentation for Gmail). There may be a support or explanation link with the error; you can also refer to it to find the exact problem.
And then, in Gmail, enable access to less secure apps by login in as the affected user. That will most probably solve the issue. So here is a guide for enabling access to less secure apps.
View all errors