I need to send an email from my sheets based on the first Column inputs (email ID's) and (which is dynamic row and gets updated based on the time). how can I return only A2:A length using the google script. Also, how can I do it in excel as well?
var formattedDate = Utilities.formatDate(new Date(), "GMT-6", "'Date: ' yyyy-MM-dd ' Time: ' HH:mm:ss ' CDT'");
var EMAIL_SENT = 'Email Success ! '+ "\n\n" + formattedDate;
/**
* Sends non-duplicate emails with data from the current spreadsheet.
*/function sendEmails2() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Script (Beta)").activate();
var startRow = 2; // First row of data to process
var numRows = 120; // Number of rows to process
// Fetch the range of cells 'A' columns
var dataRange = sheet.getRange(startRow, 1, numRows, 3);
// Fetch values for each row in the Range.
var data = dataRange.getValues();
for (var i = 0; i < data.length; ++i) {
var row = data[i];
var emailAddress = row[0]; // First column
var message = row[1]; // Second column
var emailSent = row[2]; // Third column
if (emailSent !== EMAIL_SENT) { // Prevents sending duplicates
var subject = '[Auto] The Process Has Not Yet Been Started';
if(emailSent =='')
break;
MailApp.sendEmail(emailAddress, subject, message, {htmlBody: message,
cc: '[email protected]',
bcc:'[email protected]'});
sheet.getRange(startRow + i, 3).setValue(EMAIL_SENT);
// Make sure the cell is updated right away in case the script is interrupted
Logger.log(sendEmails2);
SpreadsheetApp.flush();
}}}