【发布时间】:2020-06-03 00:31:56
【问题描述】:
我试图获得一个简单的函数,使用 on-send 函数将一些数据附加到邮件正文。
在我的清单文件中,我设置了扩展点
<ExtensionPoint xsi:type="Events">
<Event Type="ItemSend" FunctionExecution="synchronous" FunctionName="setItemBody" />
</ExtensionPoint>
我的 javascript 取自 https://docs.microsoft.com/en-us/office/dev/add-ins/outlook/outlook-on-send-addins?tabs=windows
function validateBody(event) {
console.log('validateBody');
item.body.getAsync("html", { asyncContext: event }, checkBodyOnlyOnSendCallBack);
}
// <param name="asyncResult">MessageSend event passed from the calling function.</param>
function checkBodyOnlyOnSendCallBack(asyncResult) {
var listOfBlockedWords = new Array("blockedword", "blockedword1", "blockedword2");
var 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.
var regexCheck = new RegExp('\\b(' + wordExpression + ')\\b', 'i');
var 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 });
}
但是当我在电子邮件上点击发送时,我只是不断收到“插件已阻止发送此项目。”
在浏览器调试器中我看不到它已经在 validateBody 事件中写出了 console.log。
有人知道我做错了什么吗?
【问题讨论】:
标签: outlook office-js outlook-addin