Date 基于单元格值(日期)发送电子邮件
我环顾四周,找到了一些零碎的东西,但无法把拼图拼在一起 我需要在同一列单元格列表中包含的日期前90天发送电子邮件 这就是我的数据的样子:Date 基于单元格值(日期)发送电子邮件,date,email,google-apps-script,Date,Email,Google Apps Script,我环顾四周,找到了一些零碎的东西,但无法把拼图拼在一起 我需要在同一列单元格列表中包含的日期前90天发送电子邮件 这就是我的数据的样子: 例如,脚本应在19年8月1日发送一封包含以下文本的电子邮件: 提醒生日Jon Doe 2019年11月1日 试试这个: function send(){ var ss = SpreadsheetApp.getActiveSheet(); var firstDate = new Date(); // today var data = ss.get
例如,脚本应在19年8月1日发送一封包含以下文本的电子邮件: 提醒生日Jon Doe 2019年11月1日 试试这个:
function send(){
var ss = SpreadsheetApp.getActiveSheet();
var firstDate = new Date(); // today
var data = ss.getRange("A6:C" + ss.getLastRow()).getValues(); // gets the name and the bday
for(var i = 0; i < data.length; i++){
if (time(firstDate, data[i][2]))
Logger.log("SEND"); // Here you would send the email.
else
Logger.log("NOT SENT");
}
}
function time(firstDate, secondDate){
var oneDay = 24*60*60*1000; // hours*minutes*seconds*milliseconds
var diffDays = Math.round(Math.abs((firstDate.getTime() - secondDate.getTime())/(oneDay)));
if (diffDays <= 90)
return true;
else
return false;
}
函数send(){
var ss=SpreadsheetApp.getActiveSheet();
var firstDate=新日期();//今天
var data=ss.getRange(“A6:C”+ss.getLastRow()).getValues();//获取名称和日期
对于(变量i=0;i 如果(diffDays我使用此脚本提醒银行证书过期,您可以轻松适应您的问题,对不起,我没有时间翻译
函数venciiento(){
var电子表格=SpreadsheetApp.getActive();
var sheet=spreadsheet.getActiveSheet();
var lastRow=sheet.getLastRow();
lastRow=lastRow-4;
var rango=sheet.getRange(5,2,最后一行,4);
var valores=rango.getValues();
var inicio=Date.now();
对于(var i=0;i
您是否尝试过任何代码来实现此目的?您是否将电子邮件发送给自己?
function Vencimiento() {
var spreadsheet = SpreadsheetApp.getActive();
var sheet = spreadsheet.getActiveSheet();
var lastRow = sheet.getLastRow();
lastRow = lastRow-4;
var rango = sheet.getRange(5, 2, lastRow, 4);
var valores = rango.getValues();
var inicio = Date.now();
for(var i = 0; i < lastRow; i++){
var vence = Date.parse(valores[i][2]);
var dif = Math.round((vence-inicio)/86400000) ;
switch (dif){
case 0:{enviaCorreo(valores[i][0],valores[i][1],valores[i][3],dif);break};
case 7:{enviaCorreo(valores[i][0],valores[i][1],valores[i][3],dif);break};
case 15:{enviaCorreo(valores[i][0],valores[i][1],valores[i][3],dif);break};
case 45:{enviaCorreo(valores[i][0],valores[i][1],valores[i][3],dif);break};
}
}
}
function enviaCorreo(empresa,cert,banco,dias){
var array = ["mail@gmail.com", "mail@gmail.com"];
if(dias == 0){
var str = ("El día de hoy se vencio el certificado nro: "+cert+" del banco "+banco);
Mail(array,str);
}else{
var str = ("Restan "+ dias+" para que se venza el certificado nro: "+cert+ " del banco "+banco);
Mail(array,str);}
}
function Mail(destinatarios,mensaje){
var recipient = destinatarios;
var enviar = mensaje;
GmailApp.sendEmail(destinatarios, 'Alerta Certificado bancario', enviar);
}