function sendPaymentReminders() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Sheet1"); // replace with the name of your sheet
var range = sheet.getRange("A2:D"); // replace with the range of your data
var data = range.getValues();
var today = new Date();
var messages = [];
for (var i = 0; i < data.length; i++) {
var customer = data[i][0];
var email = data[i][1];
var balance = data[i][2];
var dueDate = new Date(data[i][3]);
if (balance > 0 && today >= dueDate) {
var subject = "Payment Reminder: Your balance is overdue";
var body = "Dear " + customer + ",\n\nThis is a reminder that your balance of $" + balance.toFixed(2) + " is now overdue. Please submit payment as soon as possible to avoid late fees.\n\nThank you for your prompt attention to this matter.";
messages.push({to: email, subject: subject, body: body});
}
}
for (var j = 0; j < messages.length; j++) {
var message = messages[j];
MailApp.sendEmail(message.to, message.subject, message.body);
}
}