Отправка электронных писем на основе содержимого ячейки
function sendMyEmails() {
var ss=SpreadsheetApp.getActive();
//the next few commands create a newsheet and load it with sample data so that you do not have to. You will want to remove this and use a spreadsheet of your own choosing
var sh=ss.insertSheet();//setup
var init=[['Email','Subject','Message','Status'],['sample1@gmail.com','Email Testing','Have a great day.',''],['sample2@gmail.com','Email Testing','Have a great day.',''],['sample3@gmail.com','Email Testing','Have a great day.',''],['sample4@gmail.com','Email Testing','Have a great day.','']];//setup
sh.getRange(1,1,init.length,init[0].length).setValues(init);//setting up data
var rg=sh.getDataRange();//get data
var vA=rg.getValues();
var hObj=[];
var html='';
for(var i=0;i<vA.length;i++) {
for(var j=0;j<vA[i].length;j++) {
hObj[vA[0][j]]=vA[i][j];//this loads the object with all of the data for this row. And you can now refer to it with hObj.headertitle
}
if(!hObj.Status) {//When you supply your own data this will prevent function from sending emails more than once
html+=Utilities.formatString('<br />Email: <strong>%s</strong> Subject: <strong>%s</strong> Message: <strong>%s</strong>', hObj.Email,hObj.Subject,hObj.Message)
sh.getRange(i+1,vA[0].indexOf('Status') + 1).setValue('Done')
//MailApp.sendEmail(hObj.Email, hObj.Subject, hObj.Message);//removed for testing you will have to uncomment this line to actually send email
}
}
var ui=HtmlService.createHtmlOutput(html).setWidth(1000);
SpreadsheetApp.getUi().showModelessDialog(ui, 'Email Testing');//this provides a dialog to show you what would have been sent if everything were enabled.
}