我正在使用以下范围运行我的gmail加载项:
https://mail.google.com/
https://www.googleapis.com/auth/gmail.addons.execute
https://www.googleapis.com/auth/gmail.addons.current.action.compose
https://www.googleapis.com/auth/gmail.addons.current.message.metadata
https://www.googleapis.com/auth/script.external_request
我有一个按钮和相应的撰写动作事件,它应该从一些输入字段中读取收件人,主题和正文信息,并将此信息插入到撰写UI中。
撰写动作回调如下所示:
function autofillEmailDraft(e) {
var recipient = e.formInput.recipient;
var subject = e.formInput.subject;
var body = e.formInput.body;
GmailApp.setCurrentMessageAccessToken(e.messageMetadata.accessToken);
var draft = GmailApp.createDraft(recipient, subject, body);
// Return a built draft response. This causes Gmail to present a
// compose window to the user, pre-filled with the content specified
// above.
return CardService.newComposeActionResponseBuilder()
.setGmailDraft(draft).build();
}
单击该按钮时,插件崩溃并显示以下错误消息:TypeError: Cannot read property "accessToken" from undefined.
e.messageMetadata似乎未定义。我应该在其他地方寻找访问令牌吗?
只需删除违规行
GmailApp.setCurrentMessageAccessToken(e.messageMetadata.accessToken);
不起作用。附加组件崩溃时出现了不同的错误
Access denied: : Missing access token for authorization. Request: MailboxService.CreateDraft.
评论后更新:
这是触发撰写操作的按钮小部件的代码:
var submitButton = CardService.newTextButton()
.setTextButtonStyle(CardService.TextButtonStyle.FILLED)
.setText('Yes')
.setComposeAction(
CardService.newAction().setFunctionName('autofillEmailDraft'),
CardService.ComposedEmailType.STANDALONE_DRAFT
);
这是记录的'e'对象:
{
formInput={body=Hello},
parameters={},
draftMetadata={
toRecipients=[[email protected]],
bccRecipients=[],
ccRecipients=[]
}
}
正如此open issue所示,目前不支持从扩展撰写UI的插件填写电子邮件草稿的收件人和主题字段。