I'm a complete novice, trying to set up a timed trigger. I have a spreadsheet with a list of emails, created a script that would send an email to each of them. If I run the script manually, it works just fine. I want a trigger that will automatically send the emails every 3 months.
function sendEmails() {
var ss = SpreadsheetApp.openById("1234ID-here"); SpreadsheetApp.setActiveSpreadsheet(ss);
var sheet = SpreadsheetApp.getActiveSheet();
var dataRange = sheet.getDataRange(); // Fetch values for each row in the Range. var data = dataRange.getValues();
for (var i = 1; i < data.length; i++) {
(function (val) {
var rowData = data[i];
var emailAddress = rowData[1];
var recipient = rowData[0];
var phone = rowData[2];
var skill = rowData[3];
var address = rowData[4];
var moreinfo = rowData[5];
var message = 'Dear ' + recipient + ',\n\n' + "You signed up for the following skillshare:" + skill + "." +
"If you would like to be removed from this list, or if the following contact info has changed, please reply to this email. Otherwise we will assume no change." +
'\n\n' + address + '\n\n' + phone + '\n\n' + moreinfo + '\n\n' + 'Thanks!';
var subject = 'Skill sharing list';
MailApp.sendEmail(emailAddress, subject, message);
})(i);
}
}
If I run that, it works fine. Here's the other script I created for the trigger:
function createTimeTriggers() {
ScriptApp.newTrigger('sendEmails')
.timeBased()
.everyMinutes(1) //(to test it)
.create();
}
Running this did nothing for me, looks like it had a 90% error rate with 119 executions as soon as I ran it. Help please?
*Edit - looks like it logged the error "Script function not found: sendEmails"