Support > Forums > OpenBots Studio > How does one step through all Mailbox folders?

How does one step through all Mailbox folders?

Mike Hirshowitz

  • Reporter
  • Calender Icon February 15,2023 at 6:42 AM

This is what currently happens:

  1. In a mailbox where a few people have access, emails are received in the inbox.
  2. Anyone with access then decides to begin to action a particular mail and therefore moves it to their own folder.
  3. Completion could take many days and as parts of the process are completed, the email would then be moved to a sub-folder under their own folder.
  4. Finally, once all action has successfully been taken, the email is moved to a common "Completed" folder.

Required:

A report to enable the manager of the department to assess if something is being overlooked or is taking too long to resolve.

The automated task:

Step 1 - Step through all folders except the "Completed" folder. Step 2 - For each email in the above folders, store selected information in a Data Table for analysis.

I am not sure how to achieve Step 1. Could you please assist.

Regards Mike

This forum has 314 topics, 681 replies, and was last updated 21 days ago by Support Agent

Sahil Wadhwa

  • Participant
  • Calender Icon February 17,2023 at 7:40 AM

Hi Mike Hirshowitz,

Thanks for submitting your support query.

Please note that currently Studio does not have a command that generates the list of existing folder names in your email account dynamically. If getting the list of folder names as a static value is not an option, then we can use custom C# code to retrieve the values.

One of the advantages with OpenBots Studio, is that users are able to invoke C# code directly with any OpenBots script. Thus, giving the user access to the extensive list of C# libraries available.

In this case, we can use the Microsoft.Office.Interop.Outlook to obtain the folder names.

  1. Import the Microsoft.Office.Interop.Outlook library to your script.

  2. Define a List of string variable, this variable will hold the folder names generated, so we can use it as input for other Outlook commands

  3. Use the Evaluate Snippet command to run the snipped of C# code. Depending on the use case and requirements, the snippet may vary. In this case, I am returning the list of folders in the root Outlook account. This code can be modified to return the list of folders within a subfolder, or the list of all folders + subfolders, etc.

var vOutlookApp = new Microsoft.Office.Interop.Outlook.Application();

var vNameSpace = vOutlookApp.GetNamespace("MAPI");

var folder = vNameSpace.Folders["nataly.alvarado@OpenBots.AI"];

vFolderNames = new List();

foreach (Microsoft.Office.Interop.Outlook.Folder subFolder in folder.Folders) { vFolderNames.Add(subFolder.Name);

}

Now the vFolderNames variable contains the list of folder names extracted. So, we can use the values in the list as input for the Get Outlook Emails command.

**Note that I will raise this as a suggestion to the product team, so a Get Outlook Folders command can be added for future Studio releases.

Please let me know if you have any questions.

You are not authorized to reply, please click here to login and add your reply to this topic.