How can i fetch Email folder list from shared mailbox.
i am using below script in invoke code where it works fine but i am not sure it works on VDI or unattended BOT runner as its using Outlook interop.
Please help with any other approaches if any.
Script - Dim olApp As New Microsoft.Office.Interop.Outlook.Application
Dim olNs As Microsoft.Office.Interop.Outlook.Namespace = olApp.GetNamespace(“MAPI”)
folderList = New List(Of String)
’ Resolve shared mailbox
Dim recipient As Microsoft.Office.Interop.Outlook.Recipient = olNs.CreateRecipient(sharedMailboxName)
recipient.Resolve()
If Not recipient.Resolved Then
Throw New Exception(“Shared mailbox not resolved.”)
End If
’ Get mailbox root (parent of Inbox)
Dim inboxFolder As Microsoft.Office.Interop.Outlook.MAPIFolder =
olNs.GetSharedDefaultFolder(recipient, Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox)
Dim rootFolder As Microsoft.Office.Interop.Outlook.MAPIFolder =
CType(inboxFolder.Parent, Microsoft.Office.Interop.Outlook.MAPIFolder)
’ Use stack instead of recursive Sub (UiPath safe)
Dim folderStack As New Stack(Of Microsoft.Office.Interop.Outlook.MAPIFolder)
folderStack.Push(rootFolder)
While folderStack.Count > 0
Dim currentFolder As Microsoft.Office.Interop.Outlook.MAPIFolder = folderStack.Pop()
folderList.Add(currentFolder.FolderPath)
For i As Integer = 1 To currentFolder.Folders.Count
Dim subFolder As Microsoft.Office.Interop.Outlook.MAPIFolder =
CType(currentFolder.Folders.Item(i), Microsoft.Office.Interop.Outlook.MAPIFolder)
folderStack.Push(subFolder)
Next
End While
Thanks.