tags:

views:

104

answers:

2

i have an app that sends out email but i have to only send out 50 recipients at a time (due to server limitations)

i got a great response on my original question (http://stackoverflow.com/questions/1367843/break-up-array-into-little-arrays/1368108#1368108) on how to break up a large array into smaller arrays. split this up into arrays of 50 (and send out multiple mails)

but now there is one more level of complexity. People can enter names in the to, cc or bcc

so now the trick is, you start with 3 arrays (the to: array, the cc: array and the bcc: array)

and have to split up the mails so each mail doesn't have more than 50 total recipients.

NOTE: that there is no ideal optimization that is necessary, as long as it functionally works.

EDIT: To clarify (as there were a few questions here below, there is 3 clear arrays upfront, the "to", the "cc" and the "bcc"). if i merge them all together and then send out 50 at time, how do i know what to put in the to, cc, and bcc. i need to keep them seperate.

+2  A: 

Am I missing something? Can't you just do it like this?

foreach (var batchOf50 in SplitIntoBatches(toArray, 50))
{
    SendEmail(batchOf50, null, null);    // first param is the to list
}

foreach (var batchOf50 in SplitIntoBatches(ccArray, 50))
{
    SendEmail(null, batchOf50, null);    // second param is the cc list
}

foreach (var batchOf50 in SplitIntoBatches(bccArray, 50))
{
    SendEmail(null, null, batchOf50);    // third param is the bcc list
}

(I'll leave the implementation of SplitIntoBatches and SendEmail as an exercise for the reader!)

LukeH
A: 

i'll merge the 3 arrays into a single structured array where i'll keep the recipient type, like this

{address1, to}...{address_n, cc}...{address_m, bcc}

then, i'll split the array every 50 elements and send emails.

So i'm sure i'll send the minimal amount of email

michele
but how would you know which one to put in the "to" and which ones to put in the "bcc" if you are merging them all into one array
ooo
i've as input the 3 arrays one for each of the 3 recipients, when i'll merge them i will create a array of couples (address, recipient), so when i'll process the batch i'll know where correctly add the address, based on the flag "recipient" i've set before
michele