Outlook Add-ins UI Elements

This document explores the various UI elements available for building rich and interactive Outlook add-ins. Understanding these elements is crucial for designing user experiences that seamlessly integrate with Outlook.

Task Pane Commands

Task pane commands allow you to define buttons or menu items that, when clicked, open a task pane. This is a common way to provide persistent functionality within Outlook.

Button/Menu Item Definition

These are declared in the add-in's manifest file using the <ExtensionPoint> element.

<ExtensionPoint xsi:type="OfficeTab">
    <OfficeApp ButtonId="MyButton" />
</ExtensionPoint>

The ButtonId links the UI element to the actual add-in functionality.

Task Panes

Task panes are the primary UI surface for many Outlook add-ins. They are web pages hosted within an Outlook frame and can display information, accept user input, and interact with the Outlook item.

Task Pane Host

The task pane is typically hosted using the Office.js API.

function openTaskPane() {
    Office.addin.showTaskPane("MyTaskPane", "https://localhost:3000/taskpane.html");
}

You can specify the title of the task pane and the URL of the HTML page to load.

Contextual Commands

Contextual commands enable your add-in to appear only when relevant to the current Outlook item (e.g., an email, appointment, or contact). This provides a more targeted and less intrusive user experience.

Rule-Based Visibility

Visibility is determined by rules defined in the manifest, checking properties of the current item.

<ExtensionPoint xsi:type="MessageReadCommandSurface">
    <OfficeApp ButtonId="MyContextualButton" />
    <ExtensionPoint xsi:type="Rule" xsi:arguments="Body/Text~ContainedIn"/>
    <ExtensionPoint xsi:type="Rule" xsi:arguments="'specific keyword'"/>
</ExtensionPoint>

These rules can check for specific keywords, email addresses, or other item properties.

Dialog API

The Dialog API provides a way to open modal dialog windows from your add-in. These are useful for performing quick actions, gathering small amounts of information, or displaying messages without disrupting the main task pane flow.

Opening a Dialog

The Office.context.ui.displayDialogAsync method is used to open dialogs.

function openMyDialog() {
    Office.context.ui.displayDialogAsync(
        "https://localhost:3000/dialog.html",
        { width: "50%", height: "40%" },
        function (asyncResult) {
            if (asyncResult.status === Office.AsyncResultStatus.Succeeded) {
                var dialog = asyncResult.value;
                dialog.messageParent('Hello from the dialog!'); // Example of sending a message
                dialog.addEventHandler(Office.EventType.DialogMessageReceived, function (message) {
                    console.log("Message from dialog: " + message.data);
                });
            } else {
                console.error("Error opening dialog: " + asyncResult.error.message);
            }
        }
    );
}

You can specify the dialog's dimensions and handle messages sent between the dialog and the main add-in window.