I’m unsure as to why this app script is sending an email with only [object Object] as the whole email?
I’m not smart enough to figure this out.
function scriptattempt() {
let sheet = SpreadsheetApp.getActiveSheet();
let dataRange = sheet.getRange('A2:J');
let data = dataRange.getValues();
data.forEach((row, index) => {
let [regnumber, siccode, sicname, companyname, e1, e2, filingdeadline, e3, email, emailSent] = row;
if (!regnumber || !siccode || !sicname || !companyname || !filingdeadline || !email || emailSent === true) return;
// Validate email address before sending the email
if (!isValidEmail(email)) {
Logger.log(`Invalid email address found in row ${index + 2,9}: ${email}`);
return;
}
let subject = `Upcoming Accounting deadline ${filingdeadline} for ${companyname}.`;
let body = `Dear Sir/Madam.<br><br>
I hope this email finds you well.<br><br>
We have been notified that your filing deadline is approaching and is due by ${filingdeadline}.<br><br>
Text<br>
Text we are able to work with companies like you in the ${sicname} industry with efficiency and precision to ensure that you meet your deadlines on time.<br><br>
Get in touch if you would like more information on how we can help you.<br><br>
Warm Regards,`;
// Send the email
MailApp.sendEmail({to: email, subject, htmlbody: body});
// Mark email as sent in column
sheet.getRange(index + 2, 10).setValue(true); // +2 because index is 0-based and data starts from row 2
});
}
I’ve tried a few things but i cant seem to find what it isn’t recognising
4
In your script, please modify htmlbody
to htmlBody
. So, please modify your script as follows.
From:
MailApp.sendEmail({to: email, subject, htmlbody: body});
To:
MailApp.sendEmail({to: email, subject: subject, htmlBody: body});
Reference:
- sendEmail(message) of Class MailApp
2