Yes, you have to enable IMAP access and generate the app password to avoid this error. You can get the complete steps here – Gmail Settings