从可扩展撰写用户界面的gmail插件创建电子邮件草稿 [英] Creating draft email from gmail addon that extends compose UI

查看:92
本文介绍了从可扩展撰写用户界面的gmail插件创建电子邮件草稿的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在以下范围内运行我的gmail插件:

I'm running my gmail add-on with the following scopes:

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

我有一个按钮和相应的compose action事件,该事件应从某些输入字段读取收件人,主题和正文信息,并将此信息插入compose UI.

I have a button, and corresponding compose action event, that is supposed to read recipient, subject, and body information from some input fields and insert this info into the compose UI.

撰写操作回调如下所示:

The compose action callback looks like this:

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:无法从未定义中读取属性"accessToken".

On clicking the button, the addon crashes with the following error message: TypeError: Cannot read property "accessToken" from undefined.

e.messageMetadata似乎未定义.我是否应该在其他地方寻找访问令牌?

e.messageMetadata seems to be undefined. Should I be looking for the access token somewhere else?

只需删除违规行

GmailApp.setCurrentMessageAccessToken(e.messageMetadata.accessToken);

不起作用.加载项因其他错误而崩溃

doesn't work. The add-on crashes with a different error

Access denied: : Missing access token for authorization. Request: MailboxService.CreateDraft.

评论后更新:

这是触发编写操作的按钮小部件的代码:

This is the code for the button widget that triggers the compose action:

var submitButton = CardService.newTextButton()
      .setTextButtonStyle(CardService.TextButtonStyle.FILLED)
      .setText('Yes')
      .setComposeAction(
        CardService.newAction().setFunctionName('autofillEmailDraft'),
        CardService.ComposedEmailType.STANDALONE_DRAFT
      );

这是已记录的"e"对象:

This is the logged 'e' object:

{
    formInput={body=Hello},
    parameters={},
    draftMetadata={
        toRecipients=[abcd@example.com],
        bccRecipients=[],
        ccRecipients=[]
    }
}

推荐答案

公开问题表示,当前不支持从扩展了撰写用户界面的插件中填写电子邮件草稿的收件人和主题字段.

As this open issue indicates, filling the recipient and subject fields of an email draft from an addon that extends the compose UI is not currently supported.

这篇关于从可扩展撰写用户界面的gmail插件创建电子邮件草稿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆