web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Send email with multip...
Power Automate
Answered

Send email with multiple attachments through a Loop in PAD

(0) ShareShare
ReportReport
Posted on by 43

Hi Guys

 

Rookie again. I am trying to automate a process to send an email with multiple attachments(Excel Files). I saw something for the cloud Power Automate but nothing for Power Automate Desktop in the forums. And since I can only attach 4 files at a time due to size limit, I want to set up a loop that somehow does the trick. I was thinking along the lines;

averma_0-1627302332695.pngaverma_1-1627302378462.png

What I was trying to do here was to attach 4 files from the folder. Move the first four files in a sent folder so a loop could be created with the fresh Files[0]-[4]. Does anyone know the correct delimiter to use to separate the files( if its the correct approach. I tried , and ; and they threw an error). And what is  the best loop to use. Any screenshots would be appreciated.

 

Kind regards

Amit Verma

I have the same question (0)
  • Verified answer
    MichaelAnnis Profile Picture
    5,727 Moderator on at

    Hover over the "i" at the end.  I think I am in a slightly different command, but mine says to separate with a {Space} character. 

    MichaelAnnis_0-1627309587567.png

    Otherwise, I think you are perfectly set.  Loop through this, and you should be fine.  Make sure "Get Files from Folder" is included in your loop, that way, after you have moved out Files 0-3, the next loop will reset the file list and the next set of Files 0-3 will be a new set of Files.  

    I do not know how big your files are overall, but it's possible you could zip all the files in the folder and do one e-mail with the zip file if the zip file isn't too large.  Just another option.

    Best of luck.

  • averma Profile Picture
    43 on at

    @MichaelAnnis Thanks. The tip did help and I manage to attach multiple files.

    averma_0-1627322082544.png

     

    However the problem occurred at Move Files section where we cannot identify multiple files with commas in the same way. However, I managed to move past it by moving files through separate folders but am having difficulty when there are uneven number of files in a loop and my final files cannot be attached. In this instance I have 39 files to send and I can attach 7 files at a time, move them to a new folder and in the end I am left with  4 files which is throwing 'index out of range error'. I tried using Control Flow commands to move to the next section irrespective of error but to no avail and the 'if file exists' with 'else' command but am not able to grasp the concept fully. Any idea what can I do?

     

    In my head the syntax goes like this;

    If the file(#) does not exist, send the email with the remainder %movedfiles% ( in a separate folder)

     

    averma_1-1627322288116.pngaverma_2-1627322370772.png

     

  • MichaelAnnis Profile Picture
    5,727 Moderator on at

    You are correct again.  I don't see a command for "Get Max Index Number of %Files%", so let's create one:

    MichaelAnnis_1-1627332278850.png

    Then, I don't have a better option, so it gets convoluted, but shouldn't take too much time; use Switch->Case to identify how many attachments to add:

    MichaelAnnis_2-1627332339403.png

    Good luck.  If all these helped, please thumbs up and mark the best solution to the original question so others can find it. 

     

    Thanks,

    Mike

  • geavgous Profile Picture
    Microsoft Employee on at

    Hi Averma, 

     

    It's really great to see that you are trying to automate one of the most usual and frequent scenarios, which however might prove challenging for many of us!

    Sometimes, we don't even know how many files we want to send, or the sizes of those and our flows should include more "logic" inside to make them more self autonomous. Your solution is based on the knowledge of the number of files. However, this might change in the future.

    I would suggest to do the following instead.

    1. Use the Get Files in Folder which will create your FilesSource

    2. Set up some variables for AttachmentSizeLimit, CurrentSizeLimit where you will keep the max attach size and the current attach size to compare

    3. Create a new List that will hold the files to be attached (empty in the beggining)

     

    Since you have all those you can:

    1. Use the For Each loop, to iterate through the Files

    2. Use If inside the For Each loop to check whether the SizeLimit > CurrentSize

    a. If YES then increase CurrentSize by adding the current File.size, then add the file in the AttachList 

    b. If NO then send EMAIL and in the attachments edit box, just select the List you have filled above and after that action, insert also the "Clear List" and "Set Variable" (CurrentSize) back to 0 (zero).

    And since we are in the ELSE (NO) section, meaning that we are currently having a File to put somewhere, you can start again increasing the CurrentSize as well as adding the current file to list.

     

    I've attached a possible screenshot of how the flow could look like, but there is a lot room for improvement, since I don't cover the last iteration where the last file would not be sent. In that case you could use a new variable to keep the iteration and compare it with the Files.Count property. If those are equal, then you'll have the last file that you can send alone 🙂

     

    geavgous_0-1627335066859.png

    Let me know if that helps a bit 🙂

     

    Thanks, 

    George

     

     

  • averma Profile Picture
    43 on at

    @MichaelAnnis Thanks for your suggestion. It nudged me think alongside simple %file.count% terms. I managed to set something up for now.

    averma_0-1627337468502.pngaverma_1-1627337538296.png

     

     

    @geavgous Thanks a ton George. Yes, We ultimately are bound by the combined max file size for attachments. Thanks for the tip. I would just have to work in terms of file size now. 🙂

     

    Thank you Both. Its been a huge assistance!

  • averma Profile Picture
    43 on at

    @geavgous  Hi George

     

    Thanks for the prompt the other day. I have had a chance to work on it now. Needed the folder size to close the iteration and since there is no direct way to get it from PAD, I had to use command prompt to push a PowerShell command. Got there in the end somehow, but not without assistance and prompt from this community. 🙂

    averma_0-1628247788763.pngaverma_1-1628247874588.pngaverma_2-1628247904978.png

     

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 503 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 321 Moderator

#3
abm abm Profile Picture

abm abm 237 Most Valuable Professional

Last 30 days Overall leaderboard