Efficiently Classifying Emails for Bulk Sending

The classifyEmails function determines whether to split a set of email recipients into smaller chunks based on a predefined EMAIL_THRESHOLD. If the total count of recipients, CC, and BCC exceeds the threshold, it distributes the recipient list into smaller groups using splitToGroups, ensuring compliance with email limitations. This approach helps manage bulk email sending efficiently while preventing issues related to recipient limits.

            /**
             * @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
             */
            var classifyEmails = (recipientArr, ccArr, bccArr) => {
                var outputArr = [];
                if ((Number(recipientArr.length) + Number(ccArr.length) + Number(bccArr.length)) > Number(EMAIL_THRESHOLD)) {
                    var possibleRecipientsLengthPerEmail = Number(EMAIL_THRESHOLD) - (Number(ccArr.length) + Number(bccArr.length));
                    outputArr = splitToGroups(recipientArr, possibleRecipientsLengthPerEmail);
                } else {
                    outputArr.push(recipientArr);
                }
                return outputArr;
            };

Leave a comment

Your email address will not be published. Required fields are marked *