如果通过displayDialogAsync API打开对话框,则Microsoft Office onSend功能不允许发送邮件

时间:2018-06-20 14:51:00

标签: outlook-addin office-js office-addins outlook-web-addins

我正在尝试在Outlook加载项中实现“发送时”功能。 完成所有先决条件。正如文档中提到的那样,它可以正常工作。但是对我而言,要求是这样的:

  

如果正文包含任何“阻止词”,我想向用户显示   具有两个选项“继续”的对话框(使用displayDialogAsync API)   和“取消”。没有对话框,它允许发送邮件,但带有   对话框不起作用。

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 });
    }

0 个答案:

没有答案