关于Outlook插件自定义发送选项的技术咨询
在Outlook中添加自定义发送选项(类似Schedule Send)
核心结论
可以在Outlook的发送下拉菜单中添加自定义选项,实现“录入系统并发送”的专属操作,无需全局拦截所有发送行为。
现有方案的问题分析
- Option 1(ItemSend事件):该事件会拦截所有邮件的发送操作,无法针对单封邮件选择是否执行自定义逻辑,不符合“特定邮件触发”的需求。
- Option 2(OnMessageSend LaunchEvent):
SoftBlock模式会强制触发拦截确认,本质是全局发送拦截,而非提供可选的自定义发送入口,这也是你遇到弹窗问题的原因。
正确实现方案
通过MessageComposeCommandSurface扩展点,在发送按钮的下拉菜单中添加自定义按钮,用户可主动选择是否执行该操作。
1. 配置Manifest.xml
在邮件插件的Manifest中添加以下配置,将自定义按钮嵌入发送组:
<Hosts> <Host xsi:type="MailHost"> <DesktopFormFactor> <FunctionFile resid="residFunctionFileUrl" /> <!-- 添加自定义命令到邮件撰写界面的发送组 --> <ExtensionPoint xsi:type="MessageComposeCommandSurface"> <OfficeTab id="TabDefault"> <Group id="CustomSendGroup"> <Label resid="CustomSendGroupLabel" /> <Control xsi:type="Button" id="CustomSendButton"> <Label resid="CustomSendButtonLabel" /> <Supertip> <Title resid="CustomSendButtonTitle" /> <Description resid="CustomSendButtonDesc" /> </Supertip> <Icon> <bt:Image size="16" resid="Icon16" /> <bt:Image size="32" resid="Icon32" /> <bt:Image size="80" resid="Icon80" /> </Icon> <Action xsi:type="ExecuteFunction"> <FunctionName>customSendAndLog</FunctionName> </Action> </Control> </Group> <!-- 将自定义组定位到发送按钮所在的组之后 --> <Overrides> <Override type="OfficeTab" id="TabDefault"> <Group id="CustomSendGroup" insertAfter="GroupSend" /> </Override> </Overrides> </OfficeTab> </ExtensionPoint> </DesktopFormFactor> </Host> </Host> <!-- 补充资源定义 --> <Resources> <bt:Urls> <bt:Url id="residFunctionFileUrl" DefaultValue="https://your-addin-url/function-file.js" /> </bt:Urls> <bt:ShortStrings> <bt:String id="CustomSendGroupLabel" DefaultValue="自定义操作" /> <bt:String id="CustomSendButtonLabel" DefaultValue="录入系统并发送" /> <bt:String id="CustomSendButtonTitle" DefaultValue="录入系统并发送" /> </bt:ShortStrings> <bt:LongStrings> <bt:String id="CustomSendButtonDesc" DefaultValue="将邮件信息录入指定系统后发送邮件" /> </bt:LongStrings> <bt:Images> <bt:Image id="Icon16" DefaultValue="https://your-addin-url/icon-16.png" /> <bt:Image id="Icon32" DefaultValue="https://your-addin-url/icon-32.png" /> <bt:Image id="Icon80" DefaultValue="https://your-addin-url/icon-80.png" /> </bt:Images> </Resources>
2. 编写JavaScript逻辑
在对应的function-file.js中实现customSendAndLog函数,完成“录入系统+发送”的流程:
async function customSendAndLog() { try { // 1. 获取当前邮件的关键信息(主题、收件人、正文等) const item = Office.context.mailbox.item; const subject = await item.subject.getAsync(); const toRecipients = await item.to.getAsync(); const bodyHtml = await item.body.getAsync("html"); // 2. 将邮件信息录入你的系统(替换为实际的API调用) await fetch("https://your-system-api-url/log-email", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ subject: subject.value, to: toRecipients.value.map(recipient => recipient.emailAddress), body: bodyHtml.value }) }); // 3. 发送当前邮件 await item.sendAsync(); } catch (error) { Office.context.mailbox.item.notificationMessages.addAsync("customSendError", { type: Office.MailboxEnums.ItemNotificationMessageType.ErrorMessage, message: "操作失败:" + error.message }); } }
注意事项
- 该方案支持Outlook桌面版(Windows/macOS)和网页版,需确保使用Office.js v1.10及以上版本。
- 若需要让按钮仅在特定条件下显示(比如特定收件人、主题),可在Manifest中添加
Rule配置,或者在JS中动态控制按钮状态。
内容的提问来源于stack exchange,提问作者cashmere
相关产品推荐
相关产品推荐

