Split number of files evenly and send it to different emails

Hi Team,

I have a folder full of excel files and i need to send these excel files evenly distributed to a fixed list of email ids. Let me explain with an example.

Folder: C:\rahul\newfolder has lets assume 63 files in it. And i have let’s say 5 email ids abc1@xyz.com,abc2@xyz.com...abc5@xyz.com

The ask is i need to distribute the 63 files between these 5 email ids such that each of the 5 email ids recieve 13 files as attachment. So abc1@xyz will recieve files 1 to 13, abc2@xyz will recieve files 14 to 27 and so on.

I derived 13 files as attachment from total no. Of files / no. Of email ids =63/5 = 12.6 rounded off as 13

@supermanPunch, @ClaytonM, @Palaniyappan any help on this will be appreciated

1 Like

I’m away from my computer with Studio on it, but I can outline what you need to do.

First, create a list or array with all of your email addresses in it. For your example above, let’s call it emailList and it’s size is 5.

Then, you’ll need a ForEach looping over Directory.GetFiles(your_directory,"*.xlsx"). Create a variable named i or index and use that in the Index parameter of the ForEach.

Now it’s time for some math. We’re going to use the mod operator, which returns the remainder of a division operation. Inside the ForEach you’ll need to address the current file to index mod emailList.Size.

Here’s a breakdown of how the math works:
index = 0, 0 mod 5 = 0 -> send email to emailList[0]
index = 1, 1 mod 5 = 1 -> send email to emailList[1]
index = 2, 2 mod 5 = 2 -> send email to emailList[2]
index = 3, 3 mod 5 = 3 -> send email to emailList[3]
index = 4, 4 mod 5 = 4 -> send email to emailList[4]
index = 5, 5 mod 5 = 0 -> send email to emailList[0]
Here we can see that once the index gets large enough it will wrap back around and send to the first email address.

This continues to evenly disperse the emails through all of the addresses. The extra files 61, 62, and 63 will go to emailList[0], [1], and [2]. Then the ForEach loop will end.

@DanielMitchell thank you so much for the outline, the idea is not to send an email with 1 attachment but to send all attachments at once like, files 1 to 13 will be sent in one email to abc1@xyz.com, files 14 to 27 as attachments to abc2@xyz and so on

Instead of send email to emailList i can use add to collection activity and then i will have 5 collections which i can pass as input to send email Outlook activity

1 Like

Yes, that should work how you want it to. Sorry I misunderstood what you were getting at originally!

Have you got any Solution. I am also need help on this.
Please reply.

I have list of PDF files in a folder. Because of file Size I need to split the files by 10 and send it.Aany idea.

Hi @Mohanasaii can u explain ur query well