-
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. -
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 —
- 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