Apps 脚本 - Gmail 插件 - 获取 Gmail 邮件中的选定文本

Har*_*man 1 javascript google-apps-script

我正在开发 Gmail 插件,需要通过 Google Apps 脚本获取 Gmail 消息中选定/突出显示的文本。我可以通过以下代码获取整个消息正文,但似乎无法找到获取所选文本的方法。

function onGmailMessage(e) {

  // Get the ID of the message the user has open.
  var messageId = e.gmail.messageId;

  // Get an access token scoped to the current message and use it for GmailApp
  // calls.
  var accessToken = e.gmail.accessToken;
  GmailApp.setCurrentMessageAccessToken(accessToken);

  // Get the subject of the email.
  var message = GmailApp.getMessageById(messageId);
} 
Run Code Online (Sandbox Code Playgroud)

zig*_*hka 5

无法使用 Gmail API/Apps 脚本获取 Gmail 消息服务器端的客户端选定文本

当触发器触发时,Gmail 插件可以为您提供以下事件对象:

  • gmail.accessToken
  • gmail.bcc收件人[]
  • gmail.cc收件人[]
  • gmail.messageId
  • gmail.threadId
  • gmail.toRecipients[]

Gmail邮件资源包含以下信息:

{
  "id": string,
  "threadId": string,
  "labelIds": [
    string
  ],
  "snippet": string,
  "historyId": string,
  "internalDate": string,
  "payload": {
    object (MessagePart)
  },
  "sizeEstimate": integer,
  "raw": string
}
Run Code Online (Sandbox Code Playgroud)

因此,此信息仅适用于已保存的已发送/已接收的消息或已保存的草稿。

不幸的是,Gmail 插件(与 Docs 插件不同)无法访问客户端在草稿模块中输入/选择的文本。

如果此功能对您的应用程序至关重要,您需要改变方向并考虑使用 Chrome 扩展程序,其中可能可以使用 HTML / Javascript 抓取客户端内容。