I’m trying to set up an automated email system using Google Apps Script and Sheets. Here’s what I’m working with:
A spreadsheet with columns for email, subject, and message content
A checkbox column to select which rows to send
A common BCC address in cell F2
Sheet name is ‘ContactList’
I’ve put together a script based on some online tutorials, but it’s not working as expected. When I run it, there are no error messages, yet the emails don’t send. Here’s a simplified version of my data:
function emailDispatcher() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('ContactList');
var data = sheet.getDataRange().getValues();
var bccAddress = sheet.getRange(2, 6).getValue();
for (var i = 1; i < data.length; i++) {
if (data[i][1] === true) {
var recipient = data[i][2];
var subject = data[i][3];
var message = data[i][4];
MailApp.sendEmail(recipient, subject, message, {bcc: bccAddress});
}
}
}
Can anyone spot what might be going wrong here? I’m stumped!
hey there! i’ve had similar probs with email scripts. have u tried adding some Logger.log() statements in ur code? it could help pinpoint where things are goin wrong. also, make sure ur Gmail quota isn’t maxed out - that can stop emails from sendin without any errors. good luck!
I’ve dealt with this exact issue before, and it can be frustrating. One thing that’s not immediately obvious is that Google Apps Script has a time-based trigger limitation. If your script runs for too long, it might time out before sending all the emails.
Try breaking your email sending into smaller batches. Instead of looping through all rows at once, process maybe 20-50 at a time. You can use a time-based trigger to run the script every few minutes to handle the next batch.
Also, don’t forget to check your spam folder. Sometimes, automated emails can end up there, especially if you’re sending a lot at once.
Lastly, consider using GmailApp instead of MailApp. It gives you more control and can be more reliable for larger volumes of emails. Just remember to adjust your script permissions accordingly if you make this switch.
I’ve encountered similar issues with Google Apps Script email automation. One thing to check is your script’s authorization. Even if there are no errors, the script might not have the necessary permissions to send emails.
Try running the script manually from the script editor and see if it prompts you to authorize. If it does, go through the authorization process.
Also, double-check your spreadsheet structure. Make sure the checkbox column is actually the second column (index 1 in the script) and that it’s using proper checkboxes, not just text.
Lastly, consider adding some logging or a simple test email send at the beginning of your script to verify that the MailApp is working correctly. This can help isolate whether the issue is with the email sending or with your data processing.