Skip to main content

Notifications

Community site session details

Community site session details

Session Id : nwejmYTANK71UrgafZmbLG
Power Automate - Building Flows
Answered

Loop through subfolders in a shared mailbox

Like (0) ShareShare
ReportReport
Posted on 29 Sep 2022 14:37:17 by 15

Hello All,

I have a shared mailbox that is receiving emails from many different domains using a catch-all and forwarding rule on the domain registrar level. Next, the rule on OWA moves the email to a corresponding subfolder based on the recipient (domain)name.

To make sure there is no issue with forwarding on the domain level, once a week, I send a test email to all domains/subfolders and then manually check each of the 50 subfolders.

Now, I know I can create a Flow for each subfolder to check if the email has been received from aaa@xyz.com and then do something.
Is there a way to check all subfolders in a shared mailbox if the email hasn't been received, I would like to use single Flow for this task.

I would have to loop through each subfolder and check if there is email from aaa@xyz.com if not then send a notificaiton.

Thanks!

  • EllrickB Profile Picture
    15 on 03 Oct 2022 at 15:36:05
    Re: Loop through subfolders in a shared mailbox

    Here is a full flow if anyone can benefit from it.

     

    1.png

     

    2.png

     

    3.png

     

  • EllrickB Profile Picture
    15 on 03 Oct 2022 at 15:26:23
    Re: Loop through subfolders in a shared mailbox

    Thanks @VictorIvanidze I found this expression https://powerusers.microsoft.com/t5/General-Power-Automate/Get-emails-V3-action-if-no-results/td-p/765935 which seems work for me.

  • VictorIvanidze Profile Picture
    12,214 on 03 Oct 2022 at 13:08:22
    Re: Loop through subfolders in a shared mailbox

    In "Get emails" set top to 1.  As the output of "Get emails" is an array, check its length.

  • lbendlin Profile Picture
    7,799 Super User 2025 Season 1 on 03 Oct 2022 at 11:13:43
    Re: Loop through subfolders in a shared mailbox

    Configure two parallel actions. One gets triggered on previous step success, the other on failure.

  • EllrickB Profile Picture
    15 on 03 Oct 2022 at 10:28:26
    Re: Loop through subfolders in a shared mailbox

    I can't figure out how to create a condition which checks if email exists.

    If I check for the email body in empty subfolder condition fails with: 

    Unexpected error. Request to Azure Resource Manager failed with error: '{"error":{"code":"ActionRepetitionNotFound","message":"The specified repetition '000001-000000' of workflow action 'Condition' is not found."}}'.

     If the email is found in subfolder then condition is True. Any idea @lbendlin ?

     

    cond.png

  • lbendlin Profile Picture
    7,799 Super User 2025 Season 1 on 02 Oct 2022 at 19:35:05
    Re: Loop through subfolders in a shared mailbox

    I only know how to do that using Outlook VBA, Powershell, or a standalone C# app.   I don't think there are any options in Power Automate to do that - maybe via Graph API?

  • EllrickB Profile Picture
    15 on 01 Oct 2022 at 13:37:10
    Re: Loop through subfolders in a shared mailbox

    Thanks @lbendlin I’m curious now, how would deal with this if the folders are dynamic and new ones are added or removed.

  • Verified answer
    lbendlin Profile Picture
    7,799 Super User 2025 Season 1 on 01 Oct 2022 at 12:14:33
    Re: Loop through subfolders in a shared mailbox

    That is good. In that case you can create an array with the folder paths, and then loop over that

    lbendlin_0-1664626138606.png

    In the Get Emails step you can specify your conditions.  After the call you can check if it returned at least one email (in which case you skip to the next folder) or not (in which case you would send the notification - or collect the folder name so you can send a combined notification after all folders are checked).

  • EllrickB Profile Picture
    15 on 01 Oct 2022 at 07:24:06
    Re: Loop through subfolders in a shared mailbox

    It’s static, thanks!

  • lbendlin Profile Picture
    7,799 Super User 2025 Season 1 on 30 Sep 2022 at 23:25:39
    Re: Loop through subfolders in a shared mailbox

    Is your folder list static (ie could it be provided in an array and iterated over) or do you want a flow that automatically traverses all subfolders?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,745 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,091 Most Valuable Professional

Leaderboard