我正在尝试构建一个Outlook加载项,该加载项在发送约会邀请之前显示确认信息。 我尝试遵循https://docs.microsoft.com/en-us/outlook/add-ins/outlook-on-send-addins并使用https://github.com/OfficeDev/Outlook-Add-in-On-Send中提供的示例代码进行一些小的更改。
由于某种原因,似乎未捕获到该事件。任何人都可以帮忙吗?
我已要求Office365管理员创建已设置标志OnSendAddinsEnabled的策略
Get-CASMailbox xxx@xx.xx | fl OwaMailboxPolicy
OwaMailboxPolicy : CostEstimationPolicy
Get-OwaMailboxPolicy CostEstimationPolicy | fl onsend*
OnSendAddinsEnabled : True
manifest.xml
<?xml version="1.0" encoding="UTF-8"?>
<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">
<!-- Begin Basic Settings: Add-in metadata, used for all versions of Office unless override provided. -->
<!-- IMPORTANT! Id must be unique for your add-in, if you reuse this manifest ensure that you change this id to a new GUID. -->
<Id>080cd139-375d-4f68-bdc6-f5ab58b9b7c6</Id>
<!--Version. Updates from the store only get triggered if there is a version change. -->
<Version>1.0.0.0</Version>
<ProviderName>Kevin Ren</ProviderName>
<DefaultLocale>en-US</DefaultLocale>
<!-- The display name of your add-in. Used on the store and various places of the Office UI such as the add-ins dialog. -->
<DisplayName DefaultValue="Cost Estimation Warning" />
<Description DefaultValue="Cost Estimation Warning"/>
<Requirements>
<Sets DefaultMinVersion="1.1">
<Set Name="Mailbox" />
</Sets>
</Requirements>
<FormSettings>
<Form xsi:type="ItemEdit">
<DesktopSettings>
<SourceLocation DefaultValue="https://localhost:3000/index.html" />
</DesktopSettings>
</Form>
</FormSettings>
<Permissions>ReadWriteMailbox</Permissions>
<Rule xsi:type="RuleCollection" Mode="Or">
<Rule xsi:type="ItemIs" ItemType="Message" FormType="Edit" />
<Rule xsi:type="ItemIs" ItemType="Appointment" FormType="Edit" />
</Rule>
<VersionOverrides xmlns="http://schemas.microsoft.com/office/mailappversionoverrides" xsi:type="VersionOverridesV1_0">
<!-- On Send requires VersionOverridesV1_1 -->
<VersionOverrides xmlns="http://schemas.microsoft.com/office/mailappversionoverrides/1.1" xsi:type="VersionOverridesV1_1">
<Description resid="residAppDescription" />
<Requirements>
<bt:Sets DefaultMinVersion="1.3">
<bt:Set Name="Mailbox" />
</bt:Sets>
</Requirements>
<Hosts>
<Host xsi:type="MailHost">
<DesktopFormFactor>
<!-- The functionfile and function name to call on message send. -->
<!-- In this particular case the function calculateCostAndWarn will be called within the JavaScript code referenced in residUILessFunctionFileUrl. -->
<FunctionFile resid="residUILessFunctionFileUrl" />
<ExtensionPoint xsi:type="Events">
<Event Type="ItemSend" FunctionExecution="synchronous" FunctionName="calculateCostAndWarn" />
</ExtensionPoint>
</DesktopFormFactor>
</Host>
</Hosts>
<Resources>
<bt:Urls>
<!-- The JavaScript code is hosted on a secure and trusted web server. -->
<bt:Url id="residUILessFunctionFileUrl" DefaultValue="https://localhost:3000/index.html" ></bt:Url>
</bt:Urls>
</Resources>
</VersionOverrides>
</VersionOverrides>
</OfficeApp>
index.html
<!-- Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. -->
<!-- See LICENSE in the project root for license information -->
<!DOCTYPE html>
<html lang="en">
<head>
<title>No UI</title>
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
<script type="text/javascript" src="https://appsforoffice.microsoft.com/lib/1.1/hosted/office.debug.js"></script> -->
<script type="text/javascript" src="index.js"></script>
</head>
<body>
This page is left blank intentionally.
</body>
</html>
index.js
var mailboxItem;
Office.initialize = function (reason) {
mailboxItem = Office.context.mailbox.item;
}
// Entry point for add-in before send is allowed.
function calculateCostAndWarn(event) {
shouldChangeSubjectOnSend(event);
}
// Check if the subject should be changed. If it is already changed allow send. Otherwise change it.
// <param name="event">MessageSend event passed from the calling function.</param>
function shouldChangeSubjectOnSend(event) {
mailboxItem.subject.getAsync(
{ asyncContext: event },
function (asyncResult) {
addCCOnSend(asyncResult.asyncContext);
//console.log(asyncResult.value);
// Match string.
var checkSubject = (new RegExp(/\[Checked\]/)).test(asyncResult.value)
// Add [Checked]: to subject line.
subject = '[Checked]: ' + asyncResult.value;
// Check if a string is blank, null or undefined.
// If yes, block send and display information bar to notify sender to add a subject.
if (asyncResult.value === null || (/^\s*$/).test(asyncResult.value)) {
mailboxItem.notificationMessages.addAsync('NoSend', { type: 'errorMessage', message: 'Please enter a subject for this email.' });
asyncResult.asyncContext.completed({ allowEvent: false });
}
else {
// If can't find a [Checked]: string match in subject, call subjectOnSendChange function.
if (!checkSubject) {
subjectOnSendChange(subject, asyncResult.asyncContext);
//console.log(checkSubject);
}
else {
// Allow send.
asyncResult.asyncContext.completed({ allowEvent: true });
}
}
}
)
}
// Add a CC to the email. In this example, CC contoso@contoso.onmicrosoft.com
// <param name="event">MessageSend event passed from calling function</param>
function addCCOnSend(event) {
mailboxItem.cc.setAsync(['a@b.com'], { asyncContext: event });
}
// Check if the subject should be changed. If it is already changed allow send, otherwise change it.
// <param name="subject">Subject to set.</param>
// <param name="event">MessageSend event passed from the calling function.</param>
function subjectOnSendChange(subject, event) {
mailboxItem.subject.setAsync(
subject,
{ asyncContext: event },
function (asyncResult) {
if (asyncResult.status == Office.AsyncResultStatus.Failed) {
mailboxItem.notificationMessages.addAsync('NoSend', { type: 'errorMessage', message: 'Unable to set the subject.' });
// Block send.
asyncResult.asyncContext.completed({ allowEvent: false });
}
else {
// Allow send.
asyncResult.asyncContext.completed({ allowEvent: true });
}
});
}