Skip to main content

Notifications

Power Automate - General Discussion
Unanswered

Count number of attachments in email

(1) ShareShare
ReportReport
Posted on by 19

In flow, I want to count the number of attachments in an email(outlook) and save in a excel or may be sharepoint. The table will only have the Date and Count the number of attachments fields. Can anyone help me how to make a Power automate flow??? I am new to Power automate???

@Pstork1 

@jinivthakkar 

  • Suggested answer
    NJ-07081420-0 Profile Picture
    NJ-07081420-0 2 on at
    Count number of attachments in email
    You can use instead of filter : select , it worked for me 
    and then in compose : 
  • Pstork1 Profile Picture
    Pstork1 64,907 on at
    Re: Count number of attachments in email

    YOu don't need a loop.  Just do the filter array and then length of the result

    image.png

    Pstork1_0-1674954702983.png

     

  • AMICHAWL2 Profile Picture
    AMICHAWL2 13 on at
    Re: Count number of attachments in email

    Thank you so much for the prompt reply. I have pasted my screen to understand if I'm doing it correctly. But After doing this still, the count is not taking only PDFs. Tried using Content type, file attachment and attachments only but nothing seems to be working.

    AMICHAWL2_0-1674931105614.png

     

  • Pstork1 Profile Picture
    Pstork1 64,907 on at
    Re: Count number of attachments in email

    After retrieving the files use filter array actions for each type to filter out all the files you don't want to count.  Then use Length() on the resulting array to get the number of files.

  • AMICHAWL2 Profile Picture
    AMICHAWL2 13 on at
    Re: Count number of attachments in email

    Thank you for being so helpful Pstork1 , how do incorporate the requirements of specific Extention of the file we need? What you wrote absolutely makes sense but I'm just starting my journey in doing this flow creation so do not know how to and what to do in steps while generating this result of counts. May I request you show me how to make it possible?

  • Pstork1 Profile Picture
    Pstork1 64,907 on at
    Re: Count number of attachments in email

    If you want to run it on a schedule, then the trigger needs to be a recurrence trigger.  Once the trigger fires you'll need to do a Get Emails.  This should be filtered so only emails with attachments received within the last 24 hours are retrieved.  Now that you have the emails you'll need to process each email by getting the attachments, counting the attachments with the extensions you want and incrementing a counter variable. 

  • shantanu97 Profile Picture
    shantanu97 19 on at
    Re: Count number of attachments in email

    there are certain changes in the flow.
    1.The flow run at schedule time(9:00 am) in the morning. It should count the number of attachments in the last 24 hours. How I implement this logic?
    2. We need to count the number of attachments only certain files(.txt & .csv). Ignore all the other attachments.
    3.Which trigger I need to use??? I think I need to use "Export Email"??? Is it right??? If something else, please let me know.

  • Pstork1 Profile Picture
    Pstork1 64,907 on at
    Re: Count number of attachments in email

    The formula should be the right one.  Do you use any icons or anything in your signature?  Those will also be counted as attachments in the email. 

     

    The date and time that the email was received is included as dynamic content.  But if you want to filter based on the date and time then you will need either a condition or a filter array.

  • shantanu97 Profile Picture
    shantanu97 19 on at
    Re: Count number of attachments in email

    Is the right formula to get the number of attachments. As it is not producing the correct result. When I put 2 attachments, the compose function is producing output as 3. Can you let me know what is the correct formula.

    length(triggerBody()?['Attachments'])

    shantanu97_1-1641719587172.png

    Regarding Received Time(Date & Time email), I need to use condition. Is there any way I get received time without the use of Condition???

    shantanu97_2-1641720517440.png

     

  • Pstork1 Profile Picture
    Pstork1 64,907 on at
    Re: Count number of attachments in email

    If all you want is to get the number of attachments and the date then you don't need any Apply to Each loops. Also in the compose you need to use the Expressions tab of the dynamic content dialog box to add the length() function.  The date and time the email arrived is already available from the trigger as Received Time.

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

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,567

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,907

Leaderboard