簡體   English   中英

如何創建基於日期觸發 email 的腳本?

[英]How can I create a script which triggers an email based on a date?

再次,我對谷歌腳本不是很熟練,但是我在這里得到了很多支持,所以任何指導都將不勝感激。

我希望能夠提醒收件人一個流程應在某個日期之前進行更新。 理想情況下,希望在流程到期前 1 個月發送提醒,然后在流程到期前 1 周再次發送提醒。

我希望能夠發送一個通用的 email,其中唯一的變量是收件人姓名、email 地址、截止日期和流程名稱。

關於我如何做到這一點的任何想法或任何可行的教程。 我已將鏈接附加到應觸發電子郵件的 google 工作表

https://docs.google.com/spreadsheets/d/1Qw8WefbVkS-AQXi1CcZ0z2CL-P0oNSZYqeT40oVF6go/edit?usp=sharing

我讓你自定義文本...

function reminder() {
  var sh = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet()
  var data = sh.getDataRange().getValues()
  var d = new Date().getTime();
  for (var i=1;i<data.length;i++){
    if (data[i][4]<=new Date(d+7*24*60*60*1000) && data[i][4]>=new Date(d+5*24*60*60*1000) && data[i][6]!=''){
      MailApp.sendEmail({to:data[i][3],
        subject: 'reminder ... week', 
        htmlBody: 'Hello '+data[i][1]+' The process for '+data[i][0]+' is due to review on '+data[i][4]+' Please review the content and contact the process team before its due date if amendments are required'
      })
      sh.getRange(i+1,7).setValue('sent')
    }
    else if (data[i][4]<=new Date(d+30*24*60*60*1000)  && data[i][4]>=new Date(d+28*24*60*60*1000)  && data[i][5]!=''){
      MailApp.sendEmail({to:data[i][3],
        subject: 'reminer ... month', 
        htmlBody: 'Hello '+data[i][1]+' The process for '+data[i][0]+' is due to review on '+data[i][4]+' Please review the content and contact the process team before its due date if amendments are required'
      })
      sh.getRange(i+1,6).setValue('sent')
    }
  }
}

然后每天觸發一次

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM