Fetch Email Folder list from Shared mail box

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.

Hi @chandresh_agarwal

A better approach is to use Microsoft Graph API (recommended) or UiPath Microsoft 365 activities.

With Graph, you can call:

GET https://graph.microsoft.com/v1.0/users/{sharedMailbox}/mailFolders

This works for shared mailboxes, is unattended-safe, and doesn’t require Outlook to be installed.

If you’re using Integration Service, the Get Mail Folders activity (Microsoft 365 package) is the easiest option
It already uses Graph in the backend.

I have used something similiar before with a unattended robot on a Windows Server.

So I guess it should work, don’t know if it would be a requirement to have outlook installed though.

As I remember it you also have to have the correct imports in the workflow file for it to work.