Office.NotificationMessages interface

NotificationMessages 对象作为项目的 notificationMessages 属性返回。

注解

[ API 集:邮箱 1.3 ]

最低权限级别读取项

适用的 Outlook 模式:撰写或阅读

方法

addAsync(key, JSONmessage, options, callback)

向项目添加通知。

每封邮件中最多有 5 个通知。 设置过多的通知将返回 NumberOfNotificationMessagesExceeded 错误。

addAsync(key, JSONmessage, callback)

向项目添加通知。

每封邮件中最多有 5 个通知。 设置过多的通知将返回 NumberOfNotificationMessagesExceeded 错误。

getAllAsync(options, callback)

返回某个项目的所有项和邮件。

getAllAsync(callback)

返回某个项目的所有项和邮件。

removeAsync(key, options, callback)

删除某个项目的通知邮件。

removeAsync(key, callback)

删除某个项目的通知邮件。

replaceAsync(key, JSONmessage, options, callback)

将带有给定项的通知邮件替换为另一封邮件。

如果带有指定项的通知邮件不存在,replaceAsync 将添加通知。

replaceAsync(key, JSONmessage, callback)

将带有给定项的通知邮件替换为另一封邮件。

如果带有指定项的通知邮件不存在,replaceAsync 将添加通知。

方法详细信息

addAsync(key, JSONmessage, options, callback)

向项目添加通知。

每封邮件中最多有 5 个通知。 设置过多的通知将返回 NumberOfNotificationMessagesExceeded 错误。

addAsync(key: string, JSONmessage: NotificationMessageDetails, options: Office.AsyncContextOptions, callback?: (asyncResult: Office.AsyncResult<void>) => void): void;

参数

key

string

用于引用此通知邮件的开发人员指定的项。 开发人员可以在以后用它来修改此邮件。 其长度不能超过 32 个字符。

JSONmessage
Office.NotificationMessageDetails

一个包含要添加到项目的通知邮件的 JSON 对象。 它包含 一个 NotificationMessageDetails 对象。

options
Office.AsyncContextOptions

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

callback

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

可选。 方法完成后,使用类型的Office.AsyncResult单个参数调用在 参数中callback传递的函数。

返回

void

注解

[ API 集:邮箱 1.3 ]

最低权限级别读取项

适用的 Outlook 模式:撰写或阅读

重要说明

  • 每个加载项只允许一个 类型为 InsightMessage 的通知。 尝试添加更多将引发错误。

  • 在现代Outlook 网页版中,只能在撰写模式下添加InsightMessage通知。

  • InformationalMessage Android 版 Outlook 和 iOS 版仅支持类型。

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/35-notifications/add-getall-remove.yaml

// Adds a progress indicator to the mail item.
const id = $("#notificationId").val().toString();
const details =
  {
    type: Office.MailboxEnums.ItemNotificationMessageType.ProgressIndicator,
    message: "Progress indicator with id = " + id
  };
Office.context.mailbox.item.notificationMessages.addAsync(id, details, handleResult);

...

// Adds an informational notification to the mail item.
const id = $("#notificationId").val().toString();
const details =
  {
    type: Office.MailboxEnums.ItemNotificationMessageType.InformationalMessage,
    message: "Non-persistent informational notification message with id = " + id,
    icon: "icon1",
    persistent: false
  };
Office.context.mailbox.item.notificationMessages.addAsync(id, details, handleResult);

...

// Adds a persistent information notification to the mail item.
const id = $("#notificationId").val().toString();
const details =
  {
    type: Office.MailboxEnums.ItemNotificationMessageType.InformationalMessage,
    message: "Persistent informational notification message with id = " + id,
    icon: "icon1",
    persistent: true
  };
Office.context.mailbox.item.notificationMessages.addAsync(id, details, handleResult);

...

// Adds an error notification to the mail item.
const id = $("#notificationId").val().toString();
const details =
  {
    type: Office.MailboxEnums.ItemNotificationMessageType.ErrorMessage,
    message: "Error notification message with id = " + id
  };
Office.context.mailbox.item.notificationMessages.addAsync(id, details, handleResult);

addAsync(key, JSONmessage, callback)

向项目添加通知。

每封邮件中最多有 5 个通知。 设置过多的通知将返回 NumberOfNotificationMessagesExceeded 错误。

addAsync(key: string, JSONmessage: NotificationMessageDetails, callback?: (asyncResult: Office.AsyncResult<void>) => void): void;

参数

key

string

用于引用此通知邮件的开发人员指定的项。 开发人员可以在以后用它来修改此邮件。 其长度不能超过 32 个字符。

JSONmessage
Office.NotificationMessageDetails

一个包含要添加到项目的通知邮件的 JSON 对象。 它包含 一个 NotificationMessageDetails 对象。

callback

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

可选。 方法完成后,使用类型的Office.AsyncResult单个参数调用在 参数中callback传递的函数。

返回

void

注解

[ API 集:邮箱 1.3 ]

最低权限级别读取项

适用的 Outlook 模式:撰写或阅读

重要说明

  • 每个加载项只允许一个 类型为 InsightMessage 的通知。 尝试添加更多将引发错误。

  • 在现代Outlook 网页版中,只能在撰写模式下添加InsightMessage通知。

  • InformationalMessage Android 版 Outlook 和 iOS 版仅支持类型。

getAllAsync(options, callback)

返回某个项目的所有项和邮件。

getAllAsync(options: Office.AsyncContextOptions, callback?: (asyncResult: Office.AsyncResult<NotificationMessageDetails[]>) => void): void;

参数

options
Office.AsyncContextOptions

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

callback

(asyncResult: Office.AsyncResult<Office.NotificationMessageDetails[]>) => void

可选。 方法完成后,使用类型的Office.AsyncResult单个参数调用在 参数中callback传递的函数。 value结果的 属性是 对象的数组NotificationMessageDetails

返回

void

注解

[ API 集:邮箱 1.3 ]

最低权限级别读取项

适用的 Outlook 模式:撰写或阅读

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/35-notifications/add-getall-remove.yaml

// Gets all the notification messages and their keys for the current mail item.
Office.context.mailbox.item.notificationMessages.getAllAsync((asyncResult) => {
  if (asyncResult.status === Office.AsyncResultStatus.Failed) {
    console.log(asyncResult.error.message);
    return;
  }

  console.log(asyncResult.value);
});

getAllAsync(callback)

返回某个项目的所有项和邮件。

getAllAsync(callback?: (asyncResult: Office.AsyncResult<NotificationMessageDetails[]>) => void): void;

参数

callback

(asyncResult: Office.AsyncResult<Office.NotificationMessageDetails[]>) => void

可选。 方法完成后,使用类型的Office.AsyncResult单个参数调用在 参数中callback传递的函数。 value结果的 属性是 对象的数组NotificationMessageDetails

返回

void

注解

[ API 集:邮箱 1.3 ]

最低权限级别读取项

适用的 Outlook 模式:撰写或阅读

removeAsync(key, options, callback)

删除某个项目的通知邮件。

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

参数

key

string

要删除的通知邮件的项。

options
Office.AsyncContextOptions

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

callback

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

可选。 方法完成后,使用类型的Office.AsyncResult单个参数调用在 参数中callback传递的函数。

返回

void

注解

[ API 集:邮箱 1.3 ]

最低权限级别读取项

适用的 Outlook 模式:撰写或阅读

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/35-notifications/add-getall-remove.yaml

// Removes a notification message from the current mail item.
const id = $("#notificationId").val().toString();
Office.context.mailbox.item.notificationMessages.removeAsync(id, handleResult);

removeAsync(key, callback)

删除某个项目的通知邮件。

removeAsync(key: string, callback?: (asyncResult: Office.AsyncResult<void>) => void): void;

参数

key

string

要删除的通知邮件的项。

callback

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

可选。 方法完成后,使用类型的Office.AsyncResult单个参数调用在 参数中callback传递的函数。

返回

void

注解

[ API 集:邮箱 1.3 ]

最低权限级别读取项

适用的 Outlook 模式:撰写或阅读

replaceAsync(key, JSONmessage, options, callback)

将带有给定项的通知邮件替换为另一封邮件。

如果带有指定项的通知邮件不存在,replaceAsync 将添加通知。

replaceAsync(key: string, JSONmessage: NotificationMessageDetails, options: Office.AsyncContextOptions, callback?: (asyncResult: Office.AsyncResult<void>) => void): void;

参数

key

string

要替换的通知邮件的项。 长度不能超过 32 个字符。

JSONmessage
Office.NotificationMessageDetails

一个包含要替换现有邮件的新通知邮件的 JSON 对象。 它包含 一个 NotificationMessageDetails 对象。

options
Office.AsyncContextOptions

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

callback

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

可选。 方法完成后,使用类型的Office.AsyncResult单个参数调用在 参数中callback传递的函数。

返回

void

注解

[ API 集:邮箱 1.3 ]

最低权限级别读取项

适用的 Outlook 模式:撰写或阅读

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/35-notifications/add-getall-remove.yaml

// Replaces a notification message of a given key with another message.
const id = $("#notificationId").val().toString();
Office.context.mailbox.item.notificationMessages.replaceAsync(
  id,
  {
    type: Office.MailboxEnums.ItemNotificationMessageType.InformationalMessage,
    message: "Notification message with id = " + id + " has been replaced with an informational message.",
    icon: "icon2",
    persistent: false
  },
  handleResult);

replaceAsync(key, JSONmessage, callback)

将带有给定项的通知邮件替换为另一封邮件。

如果带有指定项的通知邮件不存在,replaceAsync 将添加通知。

replaceAsync(key: string, JSONmessage: NotificationMessageDetails, callback?: (asyncResult: Office.AsyncResult<void>) => void): void;

参数

key

string

要替换的通知邮件的项。 长度不能超过 32 个字符。

JSONmessage
Office.NotificationMessageDetails

一个包含要替换现有邮件的新通知邮件的 JSON 对象。 它包含 一个 NotificationMessageDetails 对象。

callback

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

可选。 方法完成后,使用类型的Office.AsyncResult单个参数调用在 参数中callback传递的函数。

返回

void

注解

[ API 集:邮箱 1.3 ]

最低权限级别读取项

适用的 Outlook 模式:撰写或阅读