function SendEmail() {
const activeSheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
const emailTemplate = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Settings").getRange(9, 1).getValue();
const table = activeSheet.getRange(2, 1, activeSheet.getLastRow() - 1, 40).getValues()
table.forEach(row => {
if (row[0] != "") {
const emailList = row[9]
const propertyAddress = row[1]
const emailSubject = 'Re: ' + propertyAddress
const emailPersonName = row[6]
const emailBody = emailTemplate.replace("{Name}", emailPersonName).replace("{Property Address}", propertyAddress);
const fileIdFromUrl = /https:\/\/\w*?\.google\.com\/\w*?\/d\/(.*?)\//g.exec(row[39])
const attachment = DriveApp.getFileById(fileIdFromUrl).getBlob()
MailApp.sendEmail({ name: 'Jonathan', to: emailList, subject: emailSubject, htmlBody: emailBody, attachments: [attachment], })
console.log(`Email: ${emailList} | Subject: ${emailSubject}`)
}
})
console.log(`Quota: ${MailApp.getRemainingDailyQuota()}`)
}