Office.NotificationMessages interface

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

注解

[ API 集:邮箱 1.3 ]

最低权限级别读取项

适用的 Outlook 模式:Compose或读取

重要提示:若要了解可实现的不同类型的通知消息,请参阅 为 Outlook 加载项创建通知。

方法

addAsync(key, JSONmessage, options, callback)

向项目添加通知。

addAsync(key, JSONmessage, callback)

向项目添加通知。

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)

向项目添加通知。

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 模式:Compose或读取

重要说明

  • 在 Outlook 网页版 中,在 Windows (新) 和经典) ,在 Mac 上,每条消息最多可以设置五个通知。 设置“更多”将返回错误 NumberOfNotificationMessagesExceeded 。 在 Android 版 Outlook 和 iOS 版中,每封邮件只能设置一条通知。 设置其他通知将替换上一个通知。

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

  • 在新式Outlook 网页版和新的 Outlook on Windows 中,只能在Compose模式下添加InsightMessage通知。

  • 在 Outlook on Android 和 iOS 中,仅 ProgressIndicator支持 、 InformationalMessageErrorMessage 通知类型。

  • 在撰写模式下,虽然每种通知类型的样式在其他 Outlook 客户端上有所不同,但 Android 版 Outlook 和 iOS 上的通知都使用相同的样式。 通知消息始终带有信息性图标的前缀。

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

示例

// 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 = (document.getElementById("notificationId") as HTMLInputElement).value;
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 = (document.getElementById("notificationId") as HTMLInputElement).value;
const details =
  {
    type: Office.MailboxEnums.ItemNotificationMessageType.InformationalMessage,
    message: "Non-persistent informational notification message with id = " + id,
    icon: "PG.Icon.16",
    persistent: false
  };
Office.context.mailbox.item.notificationMessages.addAsync(id, details, handleResult);

...

// Adds a persistent information notification to the mail item.
const id = (document.getElementById("notificationId") as HTMLInputElement).value;
const details =
  {
    type: Office.MailboxEnums.ItemNotificationMessageType.InformationalMessage,
    message: "Persistent informational notification message with id = " + id,
    icon: "PG.Icon.16",
    persistent: true
  };
Office.context.mailbox.item.notificationMessages.addAsync(id, details, handleResult);

...

// Adds an error notification to the mail item.
const id = (document.getElementById("notificationId") as HTMLInputElement).value;
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)

向项目添加通知。

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 模式:Compose或读取

重要说明

  • 在 Outlook 网页版 中,在 Windows (新) 和经典) ,在 Mac 上,每条消息最多可以设置五个通知。 设置“更多”将返回错误 NumberOfNotificationMessagesExceeded 。 在 Android 版 Outlook 和 iOS 版中,每封邮件只能设置一条通知。 设置其他通知将替换上一个通知。

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

  • 在新式Outlook 网页版和新的 Outlook on Windows 中,只能在Compose模式下添加InsightMessage通知。

  • 在 Outlook on Android 和 iOS 中,仅 ProgressIndicator支持 、 InformationalMessageErrorMessage 通知类型。

  • 在撰写模式下,虽然每种通知类型的样式在其他 Outlook 客户端上有所不同,但 Android 版 Outlook 和 iOS 上的通知都使用相同的样式。 通知消息始终带有信息性图标的前缀。

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

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 模式:Compose或读取

示例

// 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 模式:Compose或读取

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 模式:Compose或读取

重要提示:当前 removeAsync 使用 loadItemByIdAsync 方法加载的消息不支持方法。 有关详细信息,请参阅 在多条消息上激活 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 = (document.getElementById("notificationId") as HTMLInputElement).value;
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 模式:Compose或读取

重要提示:当前 removeAsync 使用 loadItemByIdAsync 方法加载的消息不支持方法。 有关详细信息,请参阅 在多条消息上激活 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 模式:Compose或读取

重要提示:当前 replaceAsync 使用 loadItemByIdAsync 方法加载的消息不支持方法。 有关详细信息,请参阅 在多条消息上激活 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 = (document.getElementById("notificationId") as HTMLInputElement).value;
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 模式:Compose或读取

重要提示:当前 replaceAsync 使用 loadItemByIdAsync 方法加载的消息不支持方法。 有关详细信息,请参阅 在多条消息上激活 Outlook 加载项。