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
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
index = 1, 1 mod 5 = 1 → send email to emailList
index = 2, 2 mod 5 = 2 → send email to emailList
index = 3, 3 mod 5 = 3 → send email to emailList
index = 4, 4 mod 5 = 4 → send email to emailList
index = 5, 5 mod 5 = 0 → send email to emailList 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, , and . 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 email@example.com, files 14 to 27 as attachments to abc2@xyz and so on