order: 2 id: outlook-sensitivity-labels-sensitivity-label name: Work with sensitivity labels (Compose) description: Gets and sets the sensitivity label on a message or appointment in compose mode. host: OUTLOOK api_set: Mailbox: '1.13' script: content: |- document.getElementById("get-sensitivity-label").addEventListener("click", getCurrentSensitivityLabel); document.getElementById("set-sensitivity-label").addEventListener("click", setSensitivityLabel); function getCurrentSensitivityLabel() { // This snippet gets the current mail item's sensitivity label. Office.context.sensitivityLabelsCatalog.getIsEnabledAsync((asyncResult) => { if (asyncResult.status === Office.AsyncResultStatus.Succeeded && asyncResult.value == true) { Office.context.mailbox.item.sensitivityLabel.getAsync((asyncResult) => { if (asyncResult.status === Office.AsyncResultStatus.Succeeded) { console.log(asyncResult.value); } else { console.log("Action failed with error: " + asyncResult.error.message); } }); } else { console.log("Action failed with error: " + asyncResult.error.message); } }); } function setSensitivityLabel() { // This snippet sets the sensitivity label on the current mail item. Office.context.sensitivityLabelsCatalog.getIsEnabledAsync((asyncResult) => { if (asyncResult.status === Office.AsyncResultStatus.Succeeded && asyncResult.value == true) { Office.context.sensitivityLabelsCatalog.getAsync((asyncResult) => { if (asyncResult.status === Office.AsyncResultStatus.Succeeded) { const catalog = asyncResult.value; if (catalog.length > 0) { var id = catalog[0].id; Office.context.mailbox.item.sensitivityLabel.setAsync(id, (asyncResult) => { if (asyncResult.status === Office.AsyncResultStatus.Succeeded) { console.log(asyncResult.status); } else { console.log("Action failed with error: " + asyncResult.error.message); } }); } else { console.log("Catalog list is empty"); } } else { console.log("Action failed with error: " + asyncResult.error.message); } }); } else { console.log("Action failed with error: " + asyncResult.error.message); } }); } language: typescript template: content: |-

This sample shows how to get and set the sensitivity label on a message or appointment being composed. To learn more about the sensitivity label API, see Manage the sensitivity label of your message or appointment in compose mode.

Required mode: Compose

Try it out

language: html style: content: |- body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; font-size: 14px; line-height: 1.5; padding: 10px; } section { margin-bottom: 20px; } h3 { margin-top: 0; margin-bottom: 10px; font-size: 16px; } p { margin: 0 0 10px 0; } button { background-color: #f0f0f0; color: #333333; border: 1px solid #8a8a8a; padding: 8px 16px; font-size: 14px; cursor: pointer; border-radius: 2px; margin-left: 20px; margin-bottom: 5px; min-width: 80px; display: block; } button:hover { background-color: #e0e0e0; } button:active { background-color: #d0d0d0; } input { padding: 8px; margin: 5px 0; border: 1px solid #ccc; border-radius: 2px; font-size: 14px; } .header { text-align: center; background-color: #f3f2f1; padding: 10px; } language: css libraries: |- https://officeapis.public.onecdn.static.microsoft/1/office.js https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/master/types/office-js/index.d.ts