You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Gmail插件Apps Script:客户端HTML侧边栏无法显示问题咨询

解决Gmail插件侧边栏显示"Content not available for this message"问题

开发Gmail插件时,使用Apps Script结合客户端HTML与服务端逻辑,侧边栏无法显示预期的带CSS样式的标题和按钮,反而提示"Content not available for this message",可按以下步骤排查修复:

1. 检查插件清单文件(manifest)配置

必须确保manifest.json中正确声明Gmail插件的触发器与界面配置,关联正确的服务端函数并配置足够的权限:

{
  "oauthScopes": [
    "https://www.googleapis.com/auth/gmail.addons.current.message.readonly",
    "https://www.googleapis.com/auth/script.external_request"
  ],
  "gmail": {
    "name": "Gmail Detail Plugin",
    "logoUrl": "https://example.com/logo.png",
    "contextualTriggers": [
      {
        "unconditional": {},
        "onTriggerFunction": "onGmailSidebarOpen"
      }
    ],
    "primaryColor": "#4285F4",
    "secondaryColor": "#34A853"
  },
  "manifest_version": 2
}

注意:onTriggerFunction需与服务端函数名完全匹配,授权范围要覆盖插件所需操作(如读取当前邮件)。

2. 修复HTML结构问题

你的HTML文件中<style>标签位于<head>外部,会导致样式失效,需将样式移入<head>标签内:

<!DOCTYPE html>
<html>
<head>
  <base target="_top">
  <style>
    body {
      font-family: Arial, sans-serif;
      margin: 20px;
    }
    
    h2 {
      margin-top: 0;
    }
  </style>
</head>
<body>
<h2> Gmail Detail </h2>
  <button> openDialog </button>
  <script>
    google.script.run.withSuccessHandler(onSuccess).withFailureHandler(onFailure).doSomething();

    function onSuccess() {
      console.log('Function executed successfully!');
    }

    function onFailure(error) {
      console.error('An error occurred:', error);
    }
  </script>
</body>
</html> 

3. 验证服务端函数执行

在服务端函数中添加日志,确认函数正常触发并返回正确的HtmlOutput对象:

function onGmailSidebarOpen() {
  Logger.log('Sidebar open function triggered');
  return HtmlService.createHtmlOutputFromFile('client_sidebar');
}

4. 重新部署并测试

  • 修改代码后,重新部署插件(选择「部署」->「部署为Gmail插件」,更新版本);
  • 刷新Gmail页面,重新打开侧边栏;
  • 打开Gmail开发者工具(F12),查看Console标签的JavaScript报错信息,定位潜在问题。

内容的提问来源于stack exchange,提问作者Jawad Mehmood

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 01:35:16