Outlook自定义插件激活后如何保持侧边栏始终可见?
Outlook插件跨邮件保持开启的解决方案
核心限制说明
Outlook中messageReadCommandSurface扩展点的插件是与当前阅读的单个邮件上下文绑定的,切换邮件时Outlook会销毁当前插件实例并重置上下文,这是官方的上下文隔离机制,默认无法直接让该类型插件跨邮件保持开启。
可行替代方案:改用PrimaryCommandSurface扩展点
你提到的文档中的PrimaryCommandSurface扩展点(中文译为「主命令栏扩展点」),是将插件挂载到Outlook顶部的全局命令栏,而非单个邮件的阅读窗口,这样插件打开后会独立于邮件上下文,切换邮件时不会自动关闭,直到用户手动关闭插件面板。
配置示例(修改manifest.xml)
将原有的messageReadCommandSurface扩展点替换为PrimaryCommandSurface,示例代码如下:
<ExtensionPoint xsi:type="PrimaryCommandSurface"> <CustomTab id="MyCustomPluginTab"> <Group id="MyPluginGroup"> <Label resid="Group.Label" /> <Control xsi:type="Button" id="LaunchPluginButton"> <Label resid="Button.Label" /> <Supertip> <Title resid="Supertip.Title" /> <Description resid="Supertip.Description" /> </Supertip> <Icon> <bt:Image size="16" resid="Icon.16" /> <bt:Image size="32" resid="Icon.32" /> <bt:Image size="80" resid="Icon.80" /> </Icon> <Action xsi:type="ShowTaskpane"> <SourceLocation resid="Taskpane.Url" /> </Action> </Control> </Group> <Label resid="Tab.Label" /> </CustomTab> </ExtensionPoint>
注意事项
使用该扩展点时,插件无法自动获取当前邮件的上下文数据,需要手动调用Office.js API获取:
- 调用
Office.context.mailbox.getSelectedItemsAsync()获取当前选中的邮件列表 - 通过返回的邮件ID调用
Office.context.mailbox.item.loadAsync()加载邮件详细信息
其他说明
如果必须保留messageReadCommandSurface的邮件上下文自动绑定能力,目前没有官方支持的方法让插件面板跨邮件保持开启——这是Outlook为了避免不同邮件间数据泄露设计的隔离机制,无法绕过。
内容的提问来源于stack exchange,提问作者DedicatedRam
相关产品推荐
相关产品推荐

