Sending Email to Group of Recipients

In NetSuite’s standard behavior, when using email.send, we’re not allowed to send emails to more than 10 recipients at a time. If the recipient count exceeds 10, the system throws an error, and the email fails to send.

To handle this scenario, we can send emails in batches, with each batch containing 10 recipients.

This helps avoid the NetSuite limitation were sending to more than 10 recipients using email.send throws an error.

SYNTAX:

let recipients = []; //More than 10 (ex: 50)

const MAX_RECIPIENTS = 10;

for (let i = 0; i < recipients.length; i += MAX_RECIPIENTS) {

                const chunk = recipients.slice(i, i + MAX_RECIPIENTS);

                try {

                  email.send({

                    author: 5,

                    recipients: chunk,

                    subject: ‘Subject’,

                    body: ‘Hi, nn Body. nn Thank you’,

                    attachments: [csvFile]

                  });

                  log.debug(‘Email Sent’, ‘Email with CSV sent to recipients: ‘ + chunk.join(‘, ‘));

                } catch (e) {

                  log.error(‘Error sending email to chunk’, e);

                }

              }

Leave a comment

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