I am looking to introduce a 2-minute delay after each iteration of the loop. Specifically, I want to add a delay in the process of sending emails. You can find the complete code at this link.
obj.forEach(function(row, rowIdx){
sleep(1200000);
// Emails will only be sent if the email_sent cell is empty and not hidden by a filter
if (row[EMAIL_SENT_COL] == ''){
try {
const msgObj = fillInTemplateFromObject_(emailTemplate.message, row);
// For more information on sending emails with unicode/emoji characters using GmailApp or MailApp, visit: https://developers.google.com/apps-script/reference/gmail/gmail-app#sendEmail(String,String,String,Object)
GmailApp.sendEmail(row[RECIPIENT_COL], msgObj.subject, msgObj.text, {
htmlBody: msgObj.html,
attachments: emailTemplate.attachments,
inlineImages: emailTemplate.inlineImages
});
out.push([new Date()]); // Record the date the email was sent
} catch(e) {
out.push([e.message]); // Record any errors encountered
}
} else {
out.push([row[EMAIL_SENT_COL]]); // Record that the email has already been sent
}
});