簡體   English   中英

Apps 腳本 - 將包含“執行日志”的 email 發送給腳本完成后運行的人

[英]Apps Script - Sending email that contain the "Execution log" to the person who runs the script once it's completed

我每個月都會自動運行一個腳本。 我的腳本中有多個console.log

我希望 Apps 腳本在完成后將執行日志中的響應發送給我和其他 2 封電子郵件。

下面的圖片應該總結我的要求(這只是我整個腳本的一部分)

在此先感謝您的幫助腳本完成后發送帶有控制台響應的電子郵件

嘗試這個:

function timeAndDate(){

  now = new Date();
  var firstDayPrevMonth = new Date(now.getFullYear(), now.getMonth()- 1,1);
  var firstUnix = Math.floor(new Date(firstDayPrevMonth).getTime()/1000);
  var lastDayPrevMonth = new Date(now.getFullYear(), now.getMonth(),1);
  var lastUnix = Math.floor(new Date(lastDayPrevMonth).getTime()/1000);

  Logger.log('Starting Date:',firstDayPrevMonth,'- Unix Timestamp format:',firstUnix);
  Logger.log('Ending Date:',lastDayPrevMonth,'- Unix Timestamp format:',lastUnix);
  var body = Logger.getLog();
  var recipient = Session.getActiveUser().getEmail();
  MailApp.sendEmail(recipient,'App script logs',body);

}

在使用Logger class記錄執行時使用getLog()允許您跟蹤執行,然后使用簡單的代碼您可以使用MailApp.sendEmail方法將其 email 給自己。

暫無
暫無

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

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