For Outlook Mails suggest to use Outlook activities
Install UiPath.Mail.Activities package and search for Get Outlook Mail Messages
For Office365 also install Office365 activities and use Get Mail activity
If you don’t want to use those and continue with IMAP, then check below post for reference
Hope this helps you
Thanks