[英]Displays an existing message in a separate window by gmail API?
I'm developing javascript add-on where part of functionality is reminder.我正在开发 javascript 附加组件,其中部分功能是提醒。 User entered some data and set what this email will be sent for example tomorrow.用户输入一些数据并设置这个 email 明天将发送什么。
My idea/task is to make possible what on pressing for example btn in my add-in it will open in gmail the needed email. What I have is id of the email that I need re-open in gmail.我的想法/任务是使在我的加载项中按下 btn 时它将在 gmail 中打开所需的 email 成为可能。我拥有的是 email 的 ID,我需要在 gmail 中重新打开它。
Is it possible, if you know needed email id, in the gmail to open it again by add-in in separate window?如果您知道需要 email id,是否可以在 gmail 中通过单独的 window 中的加载项再次打开它? Assuming you clicked btn in your add-on?假设您在加载项中单击了 btn?
Any ideas?有任何想法吗? btw I am using gmail api for my rest calls to app顺便说一句,我正在使用 gmail api 来调用 rest 应用程序
Depending on what you want to accomplish, I'm thinking of two alternatives.根据您想完成的任务,我正在考虑两种选择。
Use setOpenLink or setOnClickOpenLinkAction to open a URL in a new tab when a button is clicked.单击按钮时,使用setOpenLink或setOnClickOpenLinkAction在新选项卡中打开 URL。
This tab can be full size or as a popup (via setOpenAs ):此选项卡可以是全尺寸或作为弹出窗口(通过setOpenAs ):
var message = GmailApp.getMessageById(messageId);
var url = message.getThread().getPermalink();
var openLinkButton = CardService.newTextButton()
.setText('Open link')
.setOpenLink(CardService.newOpenLink()
.setUrl(url)
.setOpenAs(CardService.OpenAs.OVERLAY));
var buttonSet = CardService.newButtonSet()
.addButton(openLinkButton);
var section = CardService.newCardSection()
.addWidget(buttonSet);
var card = CardService.newCardBuilder()
.addSection(section);
return card.build();
Use setComposeAction to create and display a draft as a popup when a button is clicked.单击按钮时,使用setComposeAction创建草稿并将其显示为弹出窗口。 This draft can be standalone or a response to whatever message id you provide.此草稿可以是独立的,也可以是对您提供的任何消息 ID 的响应。
For example, in the sample below, a draft is created and displayed when clicking the button Compose Reply
:例如,在下面的示例中,单击“ Compose Reply
”按钮时会创建并显示草稿:
function createCard(e) {
var composeAction = CardService.newAction()
.setFunctionName('createReplyDraft');
var composeButton = CardService.newTextButton()
.setText('Compose Reply')
.setComposeAction(
composeAction,
CardService.ComposedEmailType.REPLY_AS_DRAFT);
var buttonSet = CardService.newButtonSet()
.addButton(composeButton);
var section = CardService.newCardSection()
.addWidget(buttonSet);
var card = CardService.newCardBuilder()
.addSection(section);
return card.build();
}
function createReplyDraft(e) {
// ...Get messageId ...
var message = GmailApp.getMessageById(messageId);
var draft = message.createDraftReply("I'm a draft!");
return CardService.newComposeActionResponseBuilder()
.setGmailDraft(draft).build();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.