问题描述
我无法让ItemSend事件适用于我正在处理的Outlook插件。我对设置错误完全感到困惑。
清单的相关部分如下:
<VersionOverrides xmlns="http://schemas.microsoft.com/office/mailappversionoverrides" xsi:type="VersionOverridesV1_0">
<VersionOverrides xmlns="http://schemas.microsoft.com/office/mailappversionoverrides/1.1" xsi:type="VersionOverridesV1_1">
<Requirements>
<bt:Sets DefaultMinVersion="1.3">
<bt:Set Name="MailBox"/>
</bt:Sets>
</Requirements>
<Hosts>
<Host xsi:type="MailHost">
<DesktopFormFactor>
<FunctionFile resid="OnSend.Url"/>
...
<!-- OnSend extension point -->
<ExtensionPoint xsi:type="Events">
<Event Type="ItemSend" FunctionExecution="synchronous" FunctionName="onSendHandler"/>
</ExtensionPoint>
</DesktopFormFactor>
</Host>
</Hosts>
<Resources>
...
<bt:Urls>
...
<bt:Url id="OnSend.Url" DefaultValue="https://localhost:3000/onsend.html"/>
...
</bt:Urls>
...
</Resources>
</VersionOverrides>
</VersionOverrides>
然后我将onsend.js与onsend.html配对,我的onsend.js非常简单:
var mailBoxItem
Office.initialize = function(reason){
mailBoxItem = Office.context.mailBox.item
}
function onSendHandler(event){
Office.context.mailBox.item.notificationMessages.addAsync("progress",{
type: "progressIndicator",message: "Processing"
})
setTimeout(()=> event.completed(),5000)
}
我的Outlook版本如下:
当我发送电子邮件时,有一小段时间会出现一条通知,指出我的加载项正在运行,但没有进度条出现,如代码中所示,并且5秒超时不会触发。如果服务器未运行,它也无法发送,因此我感觉它正在获取清单,但只是未运行该函数。
任何帮助将不胜感激!
编辑:空白清单和随附的js代码
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<OfficeApp xmlns="http://schemas.microsoft.com/office/appforoffice/1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bt="http://schemas.microsoft.com/office/officeappbasictypes/1.0" xmlns:mailappor="http://schemas.microsoft.com/office/mailappversionoverrides/1.0" xsi:type="MailApp">
<Id>d49cc7b2-77eb-4c98-978d-0ce6e3745e4d</Id>
<Version>1.0.0.0</Version>
<ProviderName>Contoso</ProviderName>
<DefaultLocale>en-US</DefaultLocale>
<displayName DefaultValue="onsendtest"/>
<Description DefaultValue="A template to get started."/>
<IconUrl DefaultValue="https://localhost:3000/assets/icon-32.png"/>
<HighResolutionIconUrl DefaultValue="https://localhost:3000/assets/icon-80.png"/>
<SupportUrl DefaultValue="https://www.contoso.com/help"/>
<AppDomains>
<AppDomain>contoso.com</AppDomain>
</AppDomains>
<Hosts>
<Host Name="MailBox"/>
</Hosts>
<Requirements>
<Sets>
<Set Name="MailBox" MinVersion="1.1"/>
</Sets>
</Requirements>
<FormSettings>
<Form xsi:type="ItemEdit">
<DesktopSettings>
<SourceLocation DefaultValue="https://localhost:3000/taskpane.html"/>
</DesktopSettings>
</Form>
</FormSettings>
<Permissions>ReadWriteItem</Permissions>
<Rule xsi:type="RuleCollection" Mode="Or">
<Rule xsi:type="ItemIs" ItemType="Message" FormType="Edit"/>
</Rule>
<disableEntityHighlighting>false</disableEntityHighlighting>
<VersionOverrides xmlns="http://schemas.microsoft.com/office/mailappversionoverrides" xsi:type="VersionOverridesV1_0">
<VersionOverrides xmlns="http://schemas.microsoft.com/office/mailappversionoverrides/1.1" xsi:type="VersionOverridesV1_1">
<Requirements>
<bt:Sets DefaultMinVersion="1.8">
<bt:Set Name="MailBox"/>
</bt:Sets>
</Requirements>
<Hosts>
<Host xsi:type="MailHost">
<DesktopFormFactor>
<FunctionFile resid="Commands.Url"/>
<ExtensionPoint xsi:type="Events">
<Event Type="ItemSend" FunctionExecution="synchronous" FunctionName="action" />
</ExtensionPoint>
<ExtensionPoint xsi:type="MessageReadCommandSurface">
<OfficeTab id="TabDefault">
<Group id="msgReadGroup">
<Label resid="GroupLabel"/>
<Control xsi:type="Button" id="msgReadOpenPaneButton">
<Label resid="TaskpaneButton.Label"/>
<Supertip>
<Title resid="TaskpaneButton.Label"/>
<Description resid="TaskpaneButton.Tooltip"/>
</Supertip>
<Icon>
<bt:Image size="16" resid="Icon.16x16"/>
<bt:Image size="32" resid="Icon.32x32"/>
<bt:Image size="80" resid="Icon.80x80"/>
</Icon>
<Action xsi:type="ShowTaskpane">
<SourceLocation resid="Taskpane.Url"/>
</Action>
</Control>
<Control xsi:type="Button" id="ActionButton">
<Label resid="ActionButton.Label"/>
<Supertip>
<Title resid="ActionButton.Label"/>
<Description resid="ActionButton.Tooltip"/>
</Supertip>
<Icon>
<bt:Image size="16" resid="Icon.16x16"/>
<bt:Image size="32" resid="Icon.32x32"/>
<bt:Image size="80" resid="Icon.80x80"/>
</Icon>
<Action xsi:type="ExecuteFunction">
<FunctionName>action</FunctionName>
</Action>
</Control>
</Group>
</OfficeTab>
</ExtensionPoint>
</DesktopFormFactor>
</Host>
</Hosts>
<Resources>
<bt:Images>
<bt:Image id="Icon.16x16" DefaultValue="https://localhost:3000/assets/icon-16.png"/>
<bt:Image id="Icon.32x32" DefaultValue="https://localhost:3000/assets/icon-32.png"/>
<bt:Image id="Icon.80x80" DefaultValue="https://localhost:3000/assets/icon-80.png"/>
</bt:Images>
<bt:Urls>
<bt:Url id="Commands.Url" DefaultValue="https://localhost:3000/commands.html"/>
<bt:Url id="Taskpane.Url" DefaultValue="https://localhost:3000/taskpane.html"/>
</bt:Urls>
<bt:ShortStrings>
<bt:String id="GroupLabel" DefaultValue="Contoso Add-in"/>
<bt:String id="TaskpaneButton.Label" DefaultValue="Show Taskpane"/>
<bt:String id="ActionButton.Label" DefaultValue="Perform an action"/>
</bt:ShortStrings>
<bt:LongStrings>
<bt:String id="TaskpaneButton.Tooltip" DefaultValue="Opens a pane displaying all available properties."/>
<bt:String id="ActionButton.Tooltip" DefaultValue="Perform an action when clicked."/>
</bt:LongStrings>
</Resources>
</VersionOverrides>
</VersionOverrides>
</OfficeApp>
Office.initialize = function(reason){
}
function action(event) {
const message = {
type: Office.MailBoxEnums.ItemNotificationMessageType.@R_861_4045@ionalMessage,message: "Performed action.",icon: "Icon.80x80",persistent: true
};
// Show a notification message
Office.context.mailBox.item.notificationMessages.replaceAsync("action",message);
// Be sure to indicate when the add-in command function is complete
event.completed({allowEvent: true})
}
编辑2:
尝试在网络上运行时出现此错误:
解决方法
对于遇到此问题的任何人,使用stock yo office webpack配置似乎不适用于ItemSend事件。不知道为什么-这可能与HtmlWebpackPlugin如何转换文件有关,我还没有深入研究。我最终要做的是触发ItemSend事件,是将以下内容添加到webpack配置的插件部分:
plugins:[
...
new CopyWebpackPlugin({
patterns:[
{
from: '[path to event handler code file].js',to: './'
}
]
})
]
您还需要在静态ItemSend html文件中引用此文件。如果您尝试将javascript和HtmlWebpackPlugin捆绑包一起传递,则该函数将不会触发。复制原始文件本身是我可以使其正常工作的唯一方法。希望这可以帮助遇到我同样问题的任何人。