Office.SensitivityLabel interface

提供用于获取或设置邮件或约会的敏感度标签的方法。 有关敏感度标签的详细信息,请参阅 了解敏感度标签

注解

API 集:邮箱 1.13

最低权限级别读取/写入项目

适用的 Outlook 模式:Compose

重要提示: 若要在加载项中使用敏感度标签功能,必须具有 Microsoft 365 E5 订阅。

若要详细了解如何在加载项中管理敏感度标签,请参阅 在撰写模式下管理邮件或约会的敏感度标签

使用方

方法

getAsync(options, callback)

获取应用于正在撰写的邮件或约会的敏感度标签的唯一标识符 (GUID) 。

getAsync(callback)

获取应用于正在撰写的邮件或约会的敏感度标签的唯一标识符 (GUID) 。

setAsync(sensitivityLabel, options, callback)

将指定的敏感度标签应用于正在撰写的邮件或约会。

setAsync(sensitivityLabel, callback)

将指定的敏感度标签应用于正在撰写的邮件或约会。

方法详细信息

getAsync(options, callback)

获取应用于正在撰写的邮件或约会的敏感度标签的唯一标识符 (GUID) 。

getAsync(options: Office.AsyncContextOptions, callback: (asyncResult: Office.AsyncResult<string>) => void): void;

参数

options
Office.AsyncContextOptions

包含以下一个或多个属性的对象文本:- asyncContext:开发人员可以在回调函数中提供他们希望访问的任何对象。

callback

(asyncResult: Office.AsyncResult<string>) => void

当该方法完成时,将使用单个参数(一个对象)asyncResultOffice.AsyncResult调用传入参数的callback函数。 在属性中 asyncResult.value 返回敏感度标签的 GUID。

返回

void

注解

API 集:邮箱 1.13

最低权限级别读取/写入项目

适用的 Outlook 模式:Compose

重要提示: 若要在加载项中使用敏感度标签功能,必须具有 Microsoft 365 E5 订阅。

若要详细了解如何在加载项中管理敏感度标签,请参阅 在撰写模式下管理邮件或约会的敏感度标签

getAsync(callback)

获取应用于正在撰写的邮件或约会的敏感度标签的唯一标识符 (GUID) 。

getAsync(callback: (asyncResult: Office.AsyncResult<string>) => void): void;

参数

callback

(asyncResult: Office.AsyncResult<string>) => void

当该方法完成时,将使用单个参数(一个对象)asyncResultOffice.AsyncResult调用传入参数的callback函数。 在属性中 asyncResult.value 返回敏感度标签的 GUID。

返回

void

注解

API 集:邮箱 1.13

最低权限级别读取/写入项目

适用的 Outlook 模式:Compose

重要提示: 若要在加载项中使用敏感度标签功能,必须具有 Microsoft 365 E5 订阅。

若要详细了解如何在加载项中管理敏感度标签,请参阅 在撰写模式下管理邮件或约会的敏感度标签

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/60-sensitivity-label/sensitivity-label.yaml

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

setAsync(sensitivityLabel, options, callback)

将指定的敏感度标签应用于正在撰写的邮件或约会。

setAsync(sensitivityLabel: string | SensitivityLabelDetails, options: Office.AsyncContextOptions, callback?: (asyncResult: Office.AsyncResult<void>) => void): void;

参数

sensitivityLabel

string | Office.SensitivityLabelDetails

要应用于正在撰写的消息或约会的敏感度标签。 参数值可以是敏感度标签的唯一标识符 (GUID) 或 SensitivityLabelDetails 对象。

options
Office.AsyncContextOptions

包含以下一个或多个属性的对象文本:- asyncContext:开发人员可以在回调函数中提供他们希望访问的任何对象。

callback

(asyncResult: Office.AsyncResult<void>) => void

可选。 当该方法完成时,将使用单个参数(一个对象)asyncResultOffice.AsyncResult调用传入参数的callback函数。

返回

void

注解

API 集:邮箱 1.13

最低权限级别读取/写入项目

适用的 Outlook 模式:Compose

重要说明

  • 若要在加载项中使用敏感度标签功能,必须具有 Microsoft 365 E5 订阅。

  • 当前使用该loadItemByIdAsync方法加载的消息不支持此setAsync方法。 有关详细信息,请参阅 在多封邮件上激活 Outlook 加载项。

提示: 若要确定可供使用的敏感度标签,请调用 Office.context.sensitivityLabelsCatalog.getAsync 该方法。

若要详细了解如何在加载项中管理敏感度标签,请参阅 在撰写模式下管理邮件或约会的敏感度标签

setAsync(sensitivityLabel, callback)

将指定的敏感度标签应用于正在撰写的邮件或约会。

setAsync(sensitivityLabel: string | SensitivityLabelDetails, callback?: (asyncResult: Office.AsyncResult<void>) => void): void;

参数

sensitivityLabel

string | Office.SensitivityLabelDetails

要应用于正在撰写的消息或约会的敏感度标签。 参数值可以是敏感度标签的唯一标识符 (GUID) 或 SensitivityLabelDetails 对象。

callback

(asyncResult: Office.AsyncResult<void>) => void

可选。 当该方法完成时,将使用单个参数(一个对象)asyncResultOffice.AsyncResult调用传入参数的callback函数。

返回

void

注解

API 集:邮箱 1.13

最低权限级别读取/写入项目

适用的 Outlook 模式:Compose

重要说明

  • 若要在加载项中使用敏感度标签功能,必须具有 Microsoft 365 E5 订阅。

  • 当前使用该loadItemByIdAsync方法加载的消息不支持此setAsync方法。 有关详细信息,请参阅 在多封邮件上激活 Outlook 加载项。

提示: 若要确定可供使用的敏感度标签,请调用 Office.context.sensitivityLabelsCatalog.getAsync 该方法。

若要详细了解如何在加载项中管理敏感度标签,请参阅 在撰写模式下管理邮件或约会的敏感度标签

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/60-sensitivity-label/sensitivity-label.yaml

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