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
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.