繁体   English   中英

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

[英]Apps Script - Gmail addon - Get selected text in Gmail message

我正在开发一个 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);
} 

使用 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
}

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM