一旦电子邮件到达收件人,它将自动调用该功能。 -失败。 据说,当收件人单击“批准”超链接时,只有应该触发的功能。
我创建了index.html,使用了HTMLService.createoutputfromfile和其他HTMLService功能,但失败了。 我不知道如何建立从客户端到服务器端脚本的通信。从Gmail到Google App脚本。
function sendEmailToApproverOne(emailAdd, action, trackSheet,rowNumber){
var form_Name = FormApp.getActiveForm().getTitle();//Get the Name of this specific Form
var btnAction = "";//---gets the button name(Approve/Acknowledge) when the recipient receives the email ----
if(action == "Approval"){
btnAction = "Approve";
}
else if(action == "Acknowledgement"){
btnAction = "Acknowledge";
}
var message = getMessage(btnAction,trackSheet,rowNumber);//----calls a function to create the email body----
GmailApp.sendEmail(emailAdd, form_Name +': For your perusal to '+ btnAction , '', {htmlBody:message});
}
function getMessage(buttonLabel,trackSheet,rowNumber) {
var htmlOutput = HtmlService.createHtmlOutputFromFile('emailBody');
var message = htmlOutput.getContent()
message = message.replace("##LINK##", pressedApprove(trackSheet,rowNumber));
message = message.replace('##BUTTONLABEL##',buttonLabel);
return message;
}
//This function: pressedApprove() is triggered when the Approver presses approve in Email button
function pressedApprove(trackSheet,rowNumber){
Logger.log("This button is clicked");
//====some code to do with tracksheet and rownumber.
}
<a href="##LINK##" id="myLink" >##BUTTONLABEL##</a>
预期将看到此功能:仅当在Gmail中单击超链接时,才会触发PressedApprove()。 我不希望每次运行代码发送Gmail时都自动拨打电话。
如何设置仅在Gmail正文中按下超链接时才触发功能的限制。
答案 0 :(得分:0)
发布您的Web应用程序:
使用查询参数打开您的Web应用
message = message.replace(
'##LINK##',
ScriptApp.getService().getUrl() +
encodeURI(
'?func=pressedApprove&trackSheet=' +
trackSheet.getId() + //use a unique id string of sheet
'&rowNumber=' +
rowNumber
)
);
function doGet(e){
var params = e.parameter;
if(params.func === 'pressedApprove'){
return pressedApprove(params.trackSheet, params.rowNumber);
}
}