[英]how do i send an email with info from a row with criteria from one of its column using google app script
我想編寫一個腳本,根據單列的條件發送電子郵件。
這是用於庫存管理系統,該系統將發送電子郵件以提醒某些物品數量較少。
例如。 如果第 5 行的 J 列是 =“提醒”,則將第 5 行 B 和 C 列的值發送到我的電子郵件。 (col B 和 C 分別是項目描述和數量計數)
我剛開始學習谷歌應用程序腳本,所以我不知道如何自己編寫它,但是從其他論壇帖子中,這就是我得到的。
var values = SpreadsheetApp.getActiveSheet().getDataRange().getValues();
values.forEach(function(row) {
var indent = row[10]; //column j
if (indent !== '') {
var EditedRange = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("store list").getRange(indent);
var Edited = EditedRange.getValue();
}
// Fetch the email address
var emailRange = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("mail").getRange("B2");
var emailAddress = emailRange.getValue();
// Send Alert Email.
var message = Edited;
var subject = 'For Action: Indent' ;
MailApp.sendEmail(emailAddress, subject, message);
});
}
我拆分了代碼並測試了電子郵件,顯然代碼的電子郵件部分有效,但檢索數據不起作用,我真的不知道如何讓它工作。
getValues()
A1
表示法的getRange()方法一個簡單的示例是:
var sheet = SpreadsheetApp.getActiveSheet();
var checkValue = sheet.getRange("J5").getValue();
if (checkValue == "reminder"){
var B5Value = sheet.getRange("B5").getValue();
var C5Value = sheet.getRange("C5").getValue();
var message = B5Value + " and " + C5Value;
var emailAddress = "you need to define the email address of the recipient either in the code or a cell of the sheet";
var subject = "Define here your subject";
MailApp.sendEmail(emailAddress, subject, message);
}
請確保花足夠的時間研究 Apps 腳本文檔,以了解此代碼並能夠進行故障排除和執行簡單的修改。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.