The Most Anticipated OfficeJS Feature is Here

If you are an Outlook Web Access developer trying to create an add-in to help mitigate the accidental release of Personally Identifiable Information (PII), you have probably been looking for a way to stop the send of the message if it does not pass a test. The functionality has not been a part of the new OfficeJS object model, until now. However, there are several things you need to know in order to set this up. Here are the general steps:

  • Use PowerShell to create a policy to enable to the OWAOnSendAddinAllUserPolicy
  • Use PowerShell to set that policy for a mailbox or group of mailboxes
  • Update your manifest file to enable the functionality and specify the event function you want to call when the user presses send
  • Write your JavaScript to properly handle the event.

NOTE: There are several caveats to this functionality. These are: you CANNOT publish an app using this functionality to the Store; this will not work on Shared mailboxes; and this will not work from any other clients, just Outlook Web Access (for now).

Create the OWAOnSendAddinAllUserPolicy

To set the policy for a user account, you need to create a policy with it enabled (or edit the default or specific policy you have applied). First, you need these steps to connect to the Exchange server as an administrator and establish a session:

Next, you need to then use PowerShell to set/configure the policy and then apply it to an account.

Once you have done, this you can then start writing the functionality into your code.

Update the Manifest file

The manifest will require a new and additional version overrides node. You will then use the FunctionFile to define an Extension point in your code. This will be a function you call. If you are not familiar with Function Files, here is a link to how to create one:

Here is what you manifest will need to look like:

  <VersionOverrides xmlns="" xsi:type="VersionOverridesV1_0">
    <!-- On Send requires VersionOverridesV1_1 -->
    <!-- -->
    <VersionOverrides xmlns="" xsi:type="VersionOverridesV1_1">
        <bt:Sets DefaultMinVersion="1.5">
          <bt:Set Name="Mailbox" />
        <Host xsi:type="MailHost">
            <!-- Location of the Functions that UI-less buttons can trigger (ExecuteFunction Actions). -->
            <FunctionFile resid="functionFile" />
            <ExtensionPoint xsi:type="Events">
              <Event Type="ItemSend" FunctionExecution="synchronous" FunctionName="onSendEvent" />

The important thing to note here is that your FunctionFile function for OnSend will need to be defined OUTSIDE the scope of the Office.initialize() function. It needs to be GLOBAL. So you simply place it in the root of your functionFile.js. However, you still need to define an Office.initialize() function in your FunctionFile and in there you probably will want to grab a reference to the mailbox, mailbox.item and the user maybe and place them in a global var as well. This way you will have access to those things in the Event method to be able to make call like body.getAsync() or subject.getAsync(), etc.

Here is how you define it:

var sendEvent;
function onSendEvent(event) {
    /// Entry point for Message onSend event
    /// Per example:
    /// Setup mailbox policy first:
    /// 1) Get sessions and commands:
    /// 2) Set policy and more info:
    /// </summary>

    /// <param name="event" type="object">ItemSend event is automatically passed by on send code to the function
    //                                    specified in the manifest.</param>
    sendEvent = event;

    // do your work here... since it will likely be ASYNC, you will want to
    // set the event handler to a global. When you are done, you will issue
    //  > sendEvent.completed({ allowEvent: true }); // to send
    //  > sendEvent.completed({ allowEvent: false }); // to block
    doSomething.Async(values, asyncComplete);

Then later in your code, you can either Cancel the send or allow the send event to occur, like this:

  function asyncCompelte() {
      // procress the result
      if(isOkToSend() == true) {
        sendEvent.completed({ allowEvent: true }); // send it
      } else {
        sendEvent.completed({ allowEvent: false }); // block it

Once you have set the policy on the mailbox, modified your manifest and then added the event function to your FunctionFile, you are good to go. I will be working on a simple demo to place on GitHub in coming weeks and will post an update when complete.

UPDATE: Here it my post with the demo:
Outlook OnSend and Dialog Sample

But I wanted to get this information out here for now. In the meantime, you can use this demo as an example of how to implement this end-to-end:

3 thoughts on “The Most Anticipated OfficeJS Feature is Here

  1. Great news, and glad to see your efforts and those of the rest of the Office team’s reach release. Well done!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s