【发布时间】:2021-10-30 07:36:32
【问题描述】:
我一直在 Chromium Edge 上测试 Outlook 加载项 On-send 功能。但由于某种原因,它从不调用函数 validateBody。
command.js
let mailboxItem;
Office.initialize = function (reason) {
mailboxItem = Office.context.mailbox.item;
};
// Determine whether the body contains a specific set of blocked words. If it contains the blocked words, block email from being sent. Otherwise allow sending.
// <param name="asyncResult">ItemSend event passed from the calling function.</param>
async function checkBodyOnlyOnSendCallBack(asyncResult) {
const listOfBlockedWords = new Array("dammit", "porra", "caralho");
const wordExpression = listOfBlockedWords.join("|");
// \b to perform a "whole words only" search using a regular expression in the form of \bword\b.
// i to perform case-insensitive search.
const regexCheck = new RegExp("\\b(" + wordExpression + ")\\b", "i");
const checkBody = regexCheck.test(asyncResult.value);
if (checkBody) {
mailboxItem.notificationMessages.addAsync("NoSend", {
type: "errorMessage",
message: "Blocked words have been found in the body of this email. Please remove them.",
});
// Block send.
asyncResult.asyncContext.completed({ allowEvent: false });
}
// Allow send.
asyncResult.asyncContext.completed({ allowEvent: true });
}
// Entry point for Contoso Message Body Checker add-in before send is allowed.
// <param name="event">ItemSend event is automatically passed by on-send code to the function specified in the manifest.</param>
function validateBody(event) {
mailboxItem.body.getAsync("html", { asyncContext: event }, checkBodyOnlyOnSendCallBack);
}
manifest.xml
<FunctionFile resid="Commands.Url" />
<ExtensionPoint xsi:type="Events">
<Event Type="ItemSend" FunctionExecution="synchronous" FunctionName="validateBody" />
</ExtensionPoint>
...
<bt:Urls>
<bt:Url id="Commands.Url" DefaultValue="https://localhost:3000/commands.html"/>
</bt:Urls>
Office.initialize 总是被调用,但从不 validateBody。但结果我只是得到消息: 很抱歉,我们无法访问测试。确保您有网络连接。如果问题仍然存在,请稍后再试。加载项测试已阻止发送此项目。
我该如何解决这个问题?
Outlook 版本: Microsoft® Outlook® 2019 MSO (16.0.14326.20164) 64 位 这是 Outlook web 上的错误消息
【问题讨论】:
-
您在运行帖子中提到的示例加载项时有任何问题吗?
-
说实话。结果和我做的一样。 On send 加载项是否需要某种类型的特殊配置?因为我的安装方式与我所做的其他方式相同。我通过清单安装加载项,但是当我尝试发送消息时,它会重复相同的行为
-
@Eugene Astafiev 我相信我理解我的错误我正在使用我的免费 Outlook 帐户 live.com 作为测试环境,所以我不能使用 On send,因为我的电子邮件不允许这样做,对吗?
-
您使用的是什么 Outlook 客户端(Mac、Win32、OWA)? OnSend 支持的客户端和平台列表可在此处找到:docs.microsoft.com/en-us/office/dev/add-ins/outlook/…
-
我正在使用 OWA。我在 Windows 上尝试过,但又遇到了一个错误,但又是一个不同的错误:... 无法完成
标签: outlook office-js outlook-addin outlook-web-addins