Google Sheets – Sending Email Notifications Based on Timeframe and Cell Data

google sheetsgoogle-apps-script

How specifically does the code found in this article need to be modified to allow for a specified email address column to inform who the reminder should go to?

I have an example spreadsheet here with the script provided from the blog post installed.

If it helps explain, my comment to the article author is as follows:

…it almost seems as though in your section “Sending the Reminder Email” that the code could reference, instead of a static email address, a cell value that meets the criteria – i.e. the adjacent date column cell is within the proper time range to trigger

And the author's response:

Yes, that’s certainly something that can be done. It’s honestly a pretty simple extension of the logic – the MailApp.sendEmail call needs to be in the loop, rather than after it.

It looks as though I have the "what" – I just need the "how". I'll take advice or a code example/modification of my installed script

Best Answer

Here's a pseudocode version of what he was saying:

What he wrote...

counter = 0

loop rows {
    if something {
        add to message
        increment counter
    }
}

if counter {
    send message to one person
}

What you need to write:

counter = 0

loop rows {
    if something {
        make message
        send message to person in row
    }
}

You will need to access the data from the email column as well. I'll leave the rest to you to work out, except to say that you should read this article on how to get the data out of your sheet efficiently.