Google apps script 谷歌应用程序脚本同时更新主题和抄送
我想打开撰写UI,并能够同时更新草稿主题/收件人/和抄送,而不是在多个操作中 Google提供的示例代码不是现成的,您需要更正错误。这是工作代码Google apps script 谷歌应用程序脚本同时更新主题和抄送,google-apps-script,gmail,gmail-contextual-gadgets,Google Apps Script,Gmail,Gmail Contextual Gadgets,我想打开撰写UI,并能够同时更新草稿主题/收件人/和抄送,而不是在多个操作中 Google提供的示例代码不是现成的,您需要更正错误。这是工作代码 /** * Compose trigger function that fires when the compose UI is * requested. Builds and returns a compose UI for inserting images. * * @param {event} e The
/**
* Compose trigger function that fires when the compose UI is
* requested. Builds and returns a compose UI for inserting images.
*
* @param {event} e The compose trigger event object. Not used in
* this example.
* @return {Card[]}
*/
function startApp(e) {
return [buildComposeCard()];
}
/**
* Build a card to display interactive buttons to allow the user to
* update the subject, and To, Cc, Bcc recipients.
*
* @return {Card}
*/
function buildComposeCard() {
var card = CardService.newCardBuilder();
var cardSection = CardService.newCardSection().setHeader('Update email');
cardSection.addWidget(
CardService.newTextButton()
.setText('Update subject')
.setOnClickAction(CardService.newAction()
.setFunctionName('applyUpdateSubjectAction')));
cardSection.addWidget(
CardService.newTextButton()
.setText('Update To recipients')
.setOnClickAction(CardService.newAction()
.setFunctionName('applyUpdateToRecipientsAction')));
cardSection.addWidget(
CardService.newTextButton()
.setText('Update Cc recipients')
.setOnClickAction(CardService.newAction()
.setFunctionName('applyUpdateCcRecipientsAction')));
cardSection.addWidget(
CardService.newTextButton()
.setText('Update Bcc recipients')
.setOnClickAction(CardService.newAction()
.setFunctionName('applyUpdateBccRecipientsAction')));
return card.addSection(cardSection).build();
}
/**
* Updates the subject field of the current email when the user clicks
* on "Update subject" in the compose UI.
*
* Note: This is not the compose action that builds a compose UI, but
* rather an action taken when the user interacts with the compose UI.
*
* @return {UpdateDraftActionResponse}
*/
function applyUpdateSubjectAction() {
// Get the new subject field of the email.
// This function is not shown in this example.
var subject = ['this is a subject'];
var response = CardService.newUpdateDraftActionResponseBuilder()
.setUpdateDraftSubjectAction(CardService.newUpdateDraftSubjectAction()
.addUpdateSubject(subject))
.build();
return response;
}
/**
* Updates the To recipients of the current email when the user clicks
* on "Update To recipients" in the compose UI.
*
* Note: This is not the compose action that builds a compose UI, but
* rather an action taken when the user interacts with the compose UI.
*
* @return {UpdateDraftActionResponse}
*/
function applyUpdateToRecipientsAction() {
// Get the new To recipients of the email.
// This function is not shown in this example.
var toRecipients = ['johhny.appleseed@gmail.com'];
var response = CardService.newUpdateDraftActionResponseBuilder()
.setUpdateDraftToRecipientsAction(CardService.newUpdateDraftToRecipientsAction()
.addUpdateToRecipients(toRecipients))
.build();
return response;
}
/**
* Updates the Cc recipients of the current email when the user clicks
* on "Update Cc recipients" in the compose UI.
*
* Note: This is not the compose action that builds a compose UI, but
* rather an action taken when the user interacts with the compose UI.
*
* @return {UpdateDraftActionResponse}
*/
function applyUpdateCcRecipientsAction() {
// Get the new Cc recipients of the email.
// This function is not shown in this example.
var ccRecipients = ['big.blue@montana.com'];
var response = CardService.newUpdateDraftActionResponseBuilder()
.setUpdateDraftCcRecipientsAction(CardService.newUpdateDraftCcRecipientsAction()
.addUpdateCcRecipients(ccRecipients))
.build();
return response;
}
/**
* Updates the Bcc recipients of the current email when the user clicks
* on "Update Bcc recipients" in the compose UI.
*
* Note: This is not the compose action that builds a compose UI, but
* rather an action taken when the user interacts with the compose UI.
*
* @return {UpdateDraftActionResponse}
*/
function applyUpdateBccRecipientsAction() {
// Get the new Bcc recipients of the email.
// This function is not shown in this example.
var bccRecipients = ['spacer@gmail.com'];
var response = CardService.newUpdateDraftActionResponseBuilder()
.setUpdateDraftBccRecipientsAction(CardService.newUpdateDraftBccRecipientsAction()
.addUpdateBccRecipients(bccRecipients))
.build();
return response;
}
当代码被打开时,它看起来像这个组合UI显示
但是
这些链接一次只能工作一个,并关闭屏幕。你必须在多个动作中执行所有动作。我希望它能够一次执行多个动作
例如,如果我单击“更新主题”,操作将起作用,撰写UI屏幕将关闭,但我不想再次打开加载项来添加CC电子邮件地址
我相信你的目标如下
function buildComposeCard() {
var card = CardService.newCardBuilder();
var cardSection = CardService.newCardSection().setHeader('Update email');
cardSection.addWidget(CardService.newTextButton().setText('Update email').setOnClickAction(CardService.newAction().setFunctionName('applyUpdateEmail')));
return card.addSection(cardSection).build();
}
- 只需单击对话框,即可运行
、applyUpdateSubjectAction()
、applyUpdateToRecipientsAction()
和ApplyUpdateRecipientsAction()
的这些函数ApplyUpdateBCCreciientsAction()
buildComposeCard()
,如下所示
function buildComposeCard() {
var card = CardService.newCardBuilder();
var cardSection = CardService.newCardSection().setHeader('Update email');
cardSection.addWidget(CardService.newTextButton().setText('Update email').setOnClickAction(CardService.newAction().setFunctionName('applyUpdateEmail')));
return card.addSection(cardSection).build();
}
并且,请添加以下功能
function applyUpdateEmail() {
var subject = ['this is a subject'];
var toRecipients = ['johhny.appleseed@gmail.com'];
var ccRecipients = ['big.blue@montana.com'];
var bccRecipients = ['spacer@gmail.com'];
return CardService.newUpdateDraftActionResponseBuilder()
.setUpdateDraftSubjectAction(CardService.newUpdateDraftSubjectAction().addUpdateSubject(subject))
.setUpdateDraftToRecipientsAction(CardService.newUpdateDraftToRecipientsAction().addUpdateToRecipients(toRecipients))
.setUpdateDraftCcRecipientsAction(CardService.newUpdateDraftCcRecipientsAction().addUpdateCcRecipients(ccRecipients))
.setUpdateDraftBccRecipientsAction(CardService.newUpdateDraftBccRecipientsAction().addUpdateBccRecipients(bccRecipients))
.build();
}
- 在此修改中,您可以在打开的对话框中看到“更新电子邮件”。单击它时,
、addUpdateSubject
、addUpdateToRecipients
和addupdateecccipients
将运行addupdatebcrecipients
- 当您修改Google Apps脚本时,请将部署修改为新版本。这样,修改后的脚本将反映到加载项中。请小心这个