79608612

Date: 2025-05-06 11:37:25
Score: 0.5
Natty:
Report link

function sendApprovedEmails() { const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Data"); // Change if your sheet name differs const data = sheet.getDataRange().getValues(); const now = new Date();

for (let i = 1; i < data.length; i++) { const [to, subject, body, cc, approval, sentFlag] = data[i];

// Skip if not approved or already sent
if (approval !== "Approved" || sentFlag === "Sent") continue;

// Send email
try {
  GmailApp.sendEmail(to, subject, body, {
    cc: cc || "",
  });
  sheet.getRange(i + 1, 6).setValue("Sent"); // Mark as Sent in Column F
} catch (error) {
  Logger.log("Error sending email for row " + (i + 1) + ": " + error);
}

// Schedule the next email in 5 minutes using a trigger
if (i + 1 < data.length) {
  ScriptApp.newTrigger("sendApprovedEmails")
    .timeBased()
    .after(5 * 60 * 1000) // 5 minutes
    .create();
  break; // Exit loop to prevent multiple emails in one run
}

} }

I need to change in the above scrept

Reasons:
  • Blacklisted phrase (0.5): I need
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Santosh N N