Find Specific Exchange Folder

I need to check if a certain subfolder exists in the main folder “Inbox” in Microsoft Exchange before proceeding to move mails to it. I am trying to use custom activities for it, but so far I’ve faced errors. I tried using “microsoft.exchange.webservices.data.folder” but it does not work. Can anyone give me the exact activity or solution required? I want to use Assign.

Thanks!!

I don’t know of any activity that can do this directly. I think I’ve seen similar forum topics asking for this before.

What you might do is put ‘Get Exchange Mail Messages’ activity in a Try-Catch block. If it ends up in an exception, you’ll know that the folder does not exist.

Alternatively, a better approach may be to establish a business rule exception which is “handled” such that the bot tries ‘Move Mail Message’ activity and if it fails, it is assumed that the folder doesn’t exist (or look for a specific exception in the catch block through trial-and-error). And then the message can be moved to a ‘Default’ folder which you definitively know exists.
This folder can later be cleaned up by a manual review team to decide where to move the failed messages.

As you say no activity can handle this (in general Exchange Activities in UiPath need a little bit of a review… my opinion). What I did was to write a code in C# (invoke code):

ExchangeService service=new ExchangeService(ExchangeVersion.Exchange2007_SP1);
service.Url=new Uri("https://outlook.office365.com/EWS/Exchange.asmx");
service.Credentials=new NetworkCredential("ACCOUNT","PASSWORD","DOMAIN");

FolderId FolderO=new FolderId(WellKnownFolderName.MsgFolderRoot,"ROOT FOLDER");
FolderView view= new FolderView(100);

foreach(Microsoft.Exchange.WebServices.Data.Folder subFolder in service.FindFolders(FolderO,view))
{
	if(subFolder.DisplayName=="NAMEFOLDERTOFIND")
	{
    }
}

Remember to check that you have the package Microsoft.Exchange.WebService and that you have imported the namespace Microsoft.Exchange.WebService.Data

1 Like