Get folder and subfolder names

  1. Is there anyway through which we can get the Folder in which an email is present?
    I have checked Outlook Email Methods, but I see only From, Date, Subject etc. but there is no Folder method.

  2. So I tried using below script from https://forum.uipath.com/t/get-outlook-mail-folders-and-sub-folders-list/109610/3, but it is throwing below exception:

RemoteException wrapping System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. —> RemoteException wrapping System.NullReferenceException: Object reference not set to an instance of an object.
at UiPathCodeRunner_cf91f033a7eb4845a7ae3111b336e014.Run(List`1 OutlookFolderNames)
— End of inner exception stack trace —

  1. When I remove OutlookFolderNames.Add(olFolderA.FolderPath) from the code, it works w/o issues and I am able to display folder names on messsage boxes.

Code:
Dim olParentFolder As Microsoft.Office.Interop.Outlook.MAPIFolder
Dim olFolderA As Microsoft.Office.Interop.Outlook.MAPIFolder
Dim olFolderB As Microsoft.Office.Interop.Outlook.MAPIFolder
Dim olFolderC As Microsoft.Office.Interop.Outlook.MAPIFolder

olApp = New Microsoft.Office.Interop.Outlook.Application
olNs = olApp.GetNamespace(“MAPI”)
olParentFolder = olNs.Folders(“test@rpa.com”).Folders(“Receipts”)

For Each olFolderA In olParentFolder.Folders
Msgbox(olFolderA.FolderPath)
OutlookFolderNames.Add(olFolderA.FolderPath)

For Each olFolderB In olFolderA.Folders
Msgbox(olFolderB.FolderPath)

For Each olFolderC In olFolderB.Folders
Msgbox(olFolderC.FolderPath)

Next
Next
Next

Arguments Screenshots:
Edit Arguments from Invoke Code:

Data Manager from right side panel:

Please help. TIA

Have you use the method below:
image

@murali.yk

I believe you will pass the folder name and then get the emails from that folder…ao you already know the folder right?

Are you looking for something else? Or are yout rying to get all folder names

Cheers

@Anil_G @jackie.yue Thanks for responding. I will only know the top folder name but there will be multiple sub folders under it. Goal is to traverse through all the emails (parent and sub folders) and then get the folder in which the email is present. Please suggest.

@murali.yk , Did you ever find a solution for this? I am needing to do the same thing–i.e. traverse an Outlook account and get the names of all folders and subfolders. With Windows (not Legacy) Office365 activities I can get a “CurrentEmail.ParentFolderId” with For Each Email (include subfolders option checked) or Get Email List, but I can’t figure out how to get a name from the Id.