Read folders inside the inbox folder mail

Hi all

I need to read how many folders are present inside inbox


I need to get how many month folders are present inside year


Hope it helps

Hi @harsha.r1

“UiPath.Mail.Activities.” Install the latest version of this package.

Add activities for Mail Automation: In your project, go to the Activities panel, and search for “Get Outlook Mail Messages.” Drag and drop this activity into the Designer panel.

Configure the “Get Outlook Mail Messages” activity:

  • Click on the “Get Outlook Mail Messages” activity to open the properties panel.
  • In the “Account” field, choose the email account that corresponds to the inbox you want to search. If you haven’t added the account, you can configure it by clicking on the “Add Account” link and following the steps.
  • In the “MailFolder” field, enter “Inbox” to specify that you want to search the inbox folder.
  • Optionally, you can add additional filters, such as the date range or the number of messages to retrieve.

Use a For Each activity: Drag and drop a “For Each” activity from the Activities panel into the Designer panel.

Configure the “For Each” activity:

  • In the “For Each” activity, select the type argument as System.Net.Mail.MailMessage from the drop-down.
  • In the “Values” field, use the output variable from the “Get Outlook Mail Messages” activity.

Count the folders: Within the “For Each” loop, you will count the subfolders. To do this, use the “Get Outlook Mail Messages” activity again and configure it similarly as you did for the inbox folder. But this time, you will set the “MailFolder” field to the current item’s “Folder” property from the “For Each” loop. This will loop through each subfolder within the inbox and retrieve the mail messages.

Use a Counter variable: Before the “For Each” loop, create a counter variable (e.g., folderCount) of type Int32 and initialize it to 0. Inside the “For Each” loop for subfolders, increment this counter variable by 1 for each subfolder processed.

Display the count: After the “For Each” loop for subfolders, you will have the count of folders in the folderCount variable. You can use a “Message Box” activity or write it to a log file to display the count.

Run the automation to get the count of folders in the inbox and its subfolders.

Hope it helps!!