I am trying to connect office365 account and it is giving this error "-ERR Logon failure: unknown user name or bad password." although user name and password both are correct.
For Office 365 you should use OAuth 2.0 flows, as Microsoft disabled basic authentication for company accounts: https://www.limilabs.com/blog/office-365-basic-auth-is-disabled
Microsoft does not allow app-passwords for company accounts. For other accounts (@hotmail.com) app-passwords still work: https://www.limilabs.com/blog/office365-app-passwords
Also make sure IMAP/POP3 are enabled (this is very important): https://www.limilabs.com/blog/office365-enable-imap-pop3-smtp