When implementing new functionalities to send emails, we have to be careful about the NetSuite limitation. A maximum of 10 recipients (recipient + cc + bcc) is only allowed.
So to tackle this issue, we have to chunk the recipients before sending the emails, such that if we got 5 recipients, 3 cc and 4 bcc emails should be sent successfully.
So we can use a function to chunk the recipients so that for the above condition, two emails would be sent.
- 1st emails with 3 recipients, 3 cc and 4 bcc.
- 2nd email with 2 recipients, 3 cc and 4 bcc.
/**
* @description Checks conditions on whether to split or not split the set of emails to chunks
* @param {Array} recipientArr | Recipient Array
* @param {Array} ccArr | CC Array
* @param {Array} bccArr | BCC Array
* @returns {Array>} outputArr
*/
let classifyEmails = (recipientArr, ccArr, bccArr) => {
let outputArr = [];
if ((Number(recipientArr.length) + Number(ccArr.length) + Number(bccArr.length)) > Number(EMAIL_THRESHOLD)) {
let possibleRecipientsLengthPerEmail = Number(EMAIL_THRESHOLD) - (Number(ccArr.length) + Number(bccArr.length));
outputArr = splitToGroups(recipientArr, possibleRecipientsLengthPerEmail);
} else {
outputArr.push(recipientArr);
}
return outputArr;
};