gpt4 book ai didi

google-apps-script - 如何将参数传递给 google-app-script 中的触发函数

转载 作者:行者123 更新时间:2023-12-02 03:04:39 31 4
gpt4 key购买 nike

我有一组收件人和必须发送邮件的预定时间。我很想知道是否有办法创建一个触发器,我可以将这些参数(收件人)传递给它

function send_mail(recipients)
{
var id = DocumentApp.getActiveDocument().getId();
for(i=0;i<recipients.length;i++)
{
var url = "https://docs.google.com/feeds/download/documents/export/Export?id="+id+"&exportFormat=html";
var param =
{
method : "get",
headers : {"Authorization": "Bearer " + ScriptApp.getOAuthToken()},
muteHttpExceptions:true,
};
var html = UrlFetchApp.fetch(url,param).getContentText();
var raw = Utilities.base64EncodeWebSafe("Subject: Test\r\n" +
"To:" +recipients[i]+"\r\n" +
"Content-Type: text/html; charset=UTF-8\r\n\r\n" +
html+"\r\n\r\n");
var message = Gmail.newMessage();
message.raw = raw;
var sentMsg = Gmail.Users.Messages.send(message, recipients[i]);
}
}
function schedule_mail(recipients,schedule)
{
ScriptApp.newTrigger("send_mail").timeBased().at(schedule).create();
}

如果 params 无法传递给 timeBased 触发器,那么还有其他解决方法吗?

最佳答案

没有直接的方法可以做到这一点。但这里有一个解决方法。
注意:这只是指令而不是实际代码。检查我在代码中的评论。

function send_mail(recipients)
{
............
............
}

function triggerHandler(e){
var triggerId = e.triggerUid;
//Iterate through all triggers and get the matching triggerId and corresponding recipient
send_mail(recipient);
}

function schedule_mail(recipients,schedule)
{
var trigger = ScriptApp.newTrigger("triggerHandler").timeBased().at(schedule).create();
var ID = trigger.getUniqueId();
//Save this ID against the recipient details in user properties
}

关于google-apps-script - 如何将参数传递给 google-app-script 中的触发函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43586897/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com