问题
I am trying to implement On Send feature in outlook Add-in. All prerequisite are done. It is working fine as normal scenario as mentioned in the documentation.But for my case the requirement is this:
If the Body contains any 'Block Word' I want to show to the user a Dialog box (using displayDialogAsync API) with two options 'Continue' and 'Cancel'. Without dialog box it allows to send Mail but with dialog it is not working.
var mailboxItem;
Office.initialize = function (reason) {
mailboxItem = Office.context.mailbox.item;
}
function validateBody(event) {
mailboxItem.body.getAsync("html", { asyncContext: event },
checkBodyOnlyOnSendCallBack);
}
function checkBodyOnlyOnSendCallBack(bodyAsyncResult) {
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.' });
var dialog;
Office.context.ui.displayDialogAsync(location.origin+'#/urlpath?queryString', {
height: 40,
width: 40,
displayInIframe: true
}, function(asyncResult) {
dialog = asyncResult.value;
//used - Office.context.ui.messageParent() to acces the following block;
dialog.addEventHandler(Office.EventType.DialogMessageReceived, function(args) {
if(args.status){
// Allow send.
bodyAsyncResult.asyncContext.completed({ allowEvent: true });
}else{
// Block send.
bodyAsyncResult.asyncContext.completed({ allowEvent: false });
}
dialog.close();
event.completed();
});
});
}else{
// Allow send.
bodyAsyncResult.asyncContext.completed({ allowEvent: true });
}
来源:https://stackoverflow.com/questions/50951091/microsoft-office-onsend-feature-does-not-allow-to-send-mail-if-dialog-is-opened