【发布时间】:2019-11-19 16:31:17
【问题描述】:
当我点击工作簿中的按钮时,我设置了一个有效的 Google 应用程序脚本以发送自动电子邮件 (GmailApp.sendEmail)。
但是,我正在尝试将脚本转换为 Google Web App,以便我组织内的任何用户都有权运行脚本并通过按下按钮触发自动电子邮件。
我对如何从 getui() 调整本地代码有点迷茫。我知道我需要添加一个诸如 doget(e) 之类的函数并部署为 Web 应用程序,但我对 Web 应用程序的了解不够,无法编辑代码。
这是我的本地工作代码:
// This constant is written in column E for rows for which an email
// has been sent successfully.
var EMAIL_SENT = 'E-MAIL SENT';
var ui = SpreadsheetApp.getUi();
/**
* Sends non-duplicate emails with data from the current spreadsheet.
*/
function email(){
var rng = SpreadsheetApp.getActiveSheet().getRange('A2:F2')
var checkvalue = SpreadsheetApp.getActiveSheet().getRange('E2').getValue();
var email = rng.getValues()[0];
var data = rng.getValues();
for (var i = 0; i < data.length; ++i) {
var row = data[i];
var emailSent = checkvalue; // emailSent confirmation cell
if (emailSent != EMAIL_SENT) { // Prevents sending duplicates
GmailApp.sendEmail(email[0], email[1], email[2]);
SpreadsheetApp.getActiveSheet().getRange('E2').setValue(EMAIL_SENT);
// Make sure the cell is updated right away in case the script is interrupted
SpreadsheetApp.flush();
}
}
}
非常感谢任何帮助!
【问题讨论】:
标签: google-apps-script google-sheets web-applications