How to access "Inbox" subfolders with "Get outlook mail message"

Hi, I’m trying to build a robot that count the email in the “inbox” and in all the subfolders of “inbox”. It works with folder at the same level (such as: draft, sent, etc.) but not on the subfolders created under “inbox”.

Any suggestion?

Hello @Giovanni_Mac ,

  1. Use the below VBA Code to get all the Inbox Subfolder Path from your Outlook (Currently Folder Path is put in a Message box, modify it to a String List Variable and do add to list,

Dim olApp As Microsoft.Office.Interop.Outlook.Application
Dim olNs As Microsoft.Office.Interop.Outlook.Namespace
Dim olParentFolder As Microsoft.Office.Interop.Outlook.MAPIFolder
Dim olFolderA As Microsoft.Office.Interop.Outlook.MAPIFolder
Dim olFolderB As Microsoft.Office.Interop.Outlook.MAPIFolder
olApp = New Microsoft.Office.Interop.Outlook.Application
olNs = olApp.GetNamespace(“MAPI”)
olParentFolder = olNs.Folders(“YourEmail@gmail.com”).Folders(“Inbox”)
For Each olFolderA In olParentFolder.Folders
Msgbox(olFolderA.FolderPath)
'Msgbox(olFolderA.FolderPath, olFolderA.Items.Count, olFolderA.Folders.Count)
For Each olFolderB In olFolderA.Folders
Msgbox(olFolderB.FolderPath)
'Msgbox(olFolderB.FolderPath, olFolderB.Items.Count)
Next
Next

  1. Use Get Outlook Mail message and Pass these folder Path one by One to get mails from each subfolder.
1 Like

Sorry, I didn’t get it. I have to put this code in the “MailFolder” field in the input? I’m not using a GMAIL account but a corporate one… it is the same?

Hi @Giovanni_Mac ,

Can you please try “Inbox/subfolder” in MailFolder, I haven’t tried it, but i guess it will work, please let me know if it does.

Thanks,
Ganesh Dongre.

Hello,

  1. Use Invoke Code activity, click on Edit code and Copy paste the below given code.

Dim olApp As Microsoft.Office.Interop.Outlook.Application
Dim olNs As Microsoft.Office.Interop.Outlook.Namespace
Dim olParentFolder As Microsoft.Office.Interop.Outlook.MAPIFolder
Dim olFolderA As Microsoft.Office.Interop.Outlook.MAPIFolder
Dim olFolderB As Microsoft.Office.Interop.Outlook.MAPIFolder
olApp = New Microsoft.Office.Interop.Outlook.Application
olNs = olApp.GetNamespace(“MAPI”)
olParentFolder = olNs.Folders(“YourEmail@outlook.com ”).Folders(“Inbox”)
For Each olFolderA In olParentFolder.Folders
Console.WriteLine(olFolderA.FolderPath)
OutlookFolderNames.Add(olFolderA.FolderPath)
Next

In the Place of YourEmail@outlook.com put your Email Id from which you wanted to retrieve mail Items.
Click on Edit Arguments and : Pass a List(Of String) OutlookFolderNames Variable to hold the value of Subfolder Paths

Refer the below Screenshots for more details :
image

Now you have all the Subfolder Paths in a List Variable

  1. Use for each loop and loop over this List,
    In for each use get outlook mail message activity pass the loop item to MailFolder property of get outlook mail message activity
    You will get mail items from required subfolder, you can perform your business logic on it.
    Later the for loop will continue with next Subfolder path and its mail messages

image

Regards,
Rohith

2 Likes

Doesn’t work for me…

Not sure how to use it but till now I’ve solved almost everything. Unique problem… Arguments and variable with List is giving me some pain

Hello @Giovanni_Mac ,

You are using wrong data type. Kindly select the below data type for argument in Invoke code.

System.Collection.Generic.List(Of String)

Hello Giovanni! Can you please tell me how did you get the main folders? (Inbox, Draft, Sent…)

Thanks!