Office.MessageCompose interface

邮件撰写模式 为 Office.context.mailbox.item

重要说明:这是一个内部 Outlook 对象,不会通过现有接口直接公开。 应将其视为 的 Office.context.mailbox.item模式。 有关详细信息,请参阅 “对象模型 ”页。

父接口:

Extends

属性

bcc

获取一个 对象,该对象提供获取或更新密 件抄送 (密件抄 送) 行收件人的方法。

根据客户端/平台 ((即 Windows、Mac 等 ) ),可能会对可以获取或更新的收件人数施加限制。 有关更多详细信息,请参阅 Recipients 对象。

body

获取一个提供用于处理项目正文的方法的对象。

categories

获取一个 对象,该对象提供用于管理项类别的方法。

重要提示:在 Outlook 网页版 中,不能使用 API 在撰写模式下管理邮件的类别。

cc

提供对邮件的抄送 (Cc) 收件人的访问权限。 对象的类型和访问级别取决于当前项的模式。

cc 属性返回一个 Recipients 对象,该对象提供用于获取或更新邮件的“抄送”行上收件人的方法。 但是,根据客户端/平台 ((即 Windows、Mac 等 ) ),可能会对可以获取或更新的收件人数施加限制。 有关更多详细信息,请参阅 Recipients 对象。

conversationId

获取包含特定消息的电子邮件会话的标识符。

如果在阅读窗体或撰写窗体的回复中激活邮件应用程序,则此属性可以获得一个整数值。 如果用户随后更改了回复邮件的主题(若发送回复),则该邮件的对话 ID 将改变且之前获取的值将不适用。

对于撰写窗体的新项目,此属性获得一个 null 值。 如果用户设置一个主题并保存该项目,conversationId 属性将返回一个值。

delayDeliveryTime

获取或设置邮件的延迟传递日期和时间。

属性 delayDeliveryTime 返回一个 DelayDeliveryTime 对象,该对象提供用于管理邮件传递日期和时间的方法。

from

获取邮件发件人的电子邮件地址。

属性 from 返回一个 From 对象,该对象提供从值获取 的方法。

inReplyTo

获取当前消息答复的原始消息的消息 ID。

internetHeaders

获取或设置消息的自定义 Internet 标头。

属性 internetHeaders 返回一个 InternetHeaders 对象,该对象提供管理消息上的 Internet 标头的方法。

若要了解详细信息,请参阅在 Outlook 外接程序中获取和设置邮件的 Internet 标头

itemType

获取实例表示的项的类型。

属性 itemType 返回枚举值之 ItemType 一,指示项目对象实例是消息还是约会。

notificationMessages

获取项目的通知邮件。

sensitivityLabel

获取要获取或设置消息 的敏感度标签 的对象。

seriesId

获取实例所属的序列的 ID。

在 Outlook 网页版 和桌面客户端中, seriesId 返回此项所属的父 (系列) 项的 Exchange Web Services (EWS) ID。 但是,在 iOS 和 Android 上,seriesId 返回父项的 REST ID。

注意:属性返回的 seriesId 标识符与 Exchange Web Services 项标识符相同。 属性 seriesId 与 Outlook REST API 使用的 Outlook ID 不同。 在使用此值进行 REST API 调用之前,应使用 Office.context.mailbox.convertToRestId进行转换。 有关详细信息,请参阅 使用 Outlook 外接程序中的 Outlook REST API。

对于没有父项(如单个约会、系列项目或会议请求)的项目,属性seriesIdnull返回 ,对于不是会议请求的任何其他项目,则返回 undefined

sessionData

在撰写模式下管理项目的 SessionData

重要提示:每个外接程序的整个 SessionData 对象限制为 50,000 个字符。

subject

获取或设置显示在项目的主题字段中的说明。

subject 属性获取或设置由电子邮件服务器发送项目时的整个主题。

subject 属性返回一个 Subject 对象,该对象提供用于获取和设置主题的方法。

to

提供对邮件的“收件人”行上的收件人的访问权限。 对象的类型和访问级别取决于当前项的模式。

to 属性返回一个 Recipients 对象,该对象提供用于获取或更新邮件的“收件人”行上收件人的方法。 但是,根据客户端/平台 ((即 Windows、Mac 等 ) ),可能会对可以获取或更新的收件人数施加限制。 有关更多详细信息,请参阅 Recipients 对象。

方法

addFileAttachmentAsync(uri, attachmentName, options, callback)

将文件作为附件添加到邮件或约会。

addFileAttachmentAsync 方法在指定的 URI 上载文件并将其附加到撰写窗体中的项目。

随后可以将该标识符与 removeAttachmentAsync 方法一同使用,以删除同一个会话中的附件。

重要提示:在 Windows 版 Outlook 的最新版本中,引入了一个 Authorization: Bearer bug,错误地将标头追加到此操作 (无论是使用此 API 还是 Outlook UI) 。 若要解决此问题,可以尝试使用要求集 1.8 中引入的 addFileAttachmentFromBase64 API。

addFileAttachmentAsync(uri, attachmentName, callback)

将文件作为附件添加到邮件或约会。

addFileAttachmentAsync 方法在指定的 URI 上载文件并将其附加到撰写窗体中的项目。

随后可以将该标识符与 removeAttachmentAsync 方法一同使用,以删除同一个会话中的附件。

重要提示:在 Windows 版 Outlook 的最新版本中,引入了一个 Authorization: Bearer bug,错误地将标头追加到此操作 (无论是使用此 API 还是 Outlook UI) 。 若要解决此问题,可以尝试使用要求集 1.8 中引入的 addFileAttachmentFromBase64 API。

addFileAttachmentFromBase64Async(base64File, attachmentName, options, callback)

将文件作为附件添加到邮件或约会。

方法 addFileAttachmentFromBase64Async 从 Base64 编码上传文件,并将其附加到撰写窗体中的项目。 此方法返回 对象中的 asyncResult.value 附件标识符。

随后可以将该标识符与 removeAttachmentAsync 方法一同使用,以删除同一个会话中的附件。

addFileAttachmentFromBase64Async(base64File, attachmentName, callback)

将文件作为附件添加到邮件或约会。

方法 addFileAttachmentFromBase64Async 从 Base64 编码上传文件,并将其附加到撰写窗体中的项目。 此方法返回 对象中的 asyncResult.value 附件标识符。

随后可以将该标识符与 removeAttachmentAsync 方法一同使用,以删除同一个会话中的附件。

addHandlerAsync(eventType, handler, options, callback)

添加支持事件的事件处理程序。 注意:事件仅适用于任务窗格实现。

有关支持的事件,请参阅 Item 对象模型 事件部分

addHandlerAsync(eventType, handler, callback)

添加支持事件的事件处理程序。 注意:事件仅适用于任务窗格实现。

有关支持的事件,请参阅 Item 对象模型 事件部分

addItemAttachmentAsync(itemId, attachmentName, options, callback)

将 Exchange 项目(如邮件)作为附件添加到邮件或约会。

addItemAttachmentAsync 方法将包含指定 Exchange 标识符的项目附加到撰写窗体中的项目。 如果指定回调函数,则会使用一个参数调用 方法, asyncResult该参数包含附件标识符或指示附加项时发生的任何错误的代码。 如果需要,可以使用 options 参数将状态信息传递给回调函数。

随后可以将该标识符与 removeAttachmentAsync 方法一同使用,以删除同一个会话中的附件。

如果 Office 加载项是在 Outlook 网页版中运行,addItemAttachmentAsync 方法可以将项附加到除正在编辑的项外的项;但既不支持也不建议这样做。

addItemAttachmentAsync(itemId, attachmentName, callback)

将 Exchange 项目(如邮件)作为附件添加到邮件或约会。

addItemAttachmentAsync 方法将包含指定 Exchange 标识符的项目附加到撰写窗体中的项目。 如果指定回调函数,则会使用一个参数调用 方法, asyncResult该参数包含附件标识符或指示附加项时发生的任何错误的代码。 如果需要,可以使用 options 参数将状态信息传递给回调函数。

随后可以将该标识符与 removeAttachmentAsync 方法一同使用,以删除同一个会话中的附件。

如果 Office 加载项是在 Outlook 网页版中运行,addItemAttachmentAsync 方法可以将项附加到除正在编辑的项外的项;但既不支持也不建议这样做。

close()

关闭当前正在撰写的项目。

close 方法的行为取决于要撰写的项目的当前状态。 如果项有未保存的更改,客户端会提示用户保存、放弃或关闭操作。

在 Outlook 桌面客户端中 close , 方法对阅读窗格中的答复没有影响。

closeAsync(options, callback)

使用 放弃未保存的更改的选项关闭正在撰写的当前消息。 正在撰写的邮件可以是新邮件、答复或现有草稿。

closeAsync(callback)

关闭正在撰写的当前新邮件。

撰写的新邮件的行为取决于该消息是否包含任何未保存的更改。 如果未进行任何更改,则会关闭消息,而不会显示保存对话框。 另一方面,如果消息包含未保存的更改,将显示一个保存对话框,提示用户保存草稿、放弃更改或取消操作。

disableClientSignatureAsync(options, callback)

禁用 Outlook 客户端签名。

此方法的行为取决于加载项运行的客户端。

  • 在 Windows 版和 Mac 版 Outlook 中,发送帐户的 “新建邮件 ”和 “答复/转发 ”部分下的签名设置为 (无)

  • 在 Outlook 网页版 中,将禁用新邮件、答复和转发的签名选项。 方法也会禁用所选的签名。

  • 在 Android 版和 iOS 版 Outlook 中,将清除移动设备上保存的签名。

disableClientSignatureAsync(callback)

禁用 Outlook 客户端签名。

此方法的行为取决于加载项运行的客户端。

  • 在 Windows 版和 Mac 版 Outlook 中,发送帐户的 “新建邮件 ”和 “答复/转发 ”部分下的签名设置为 (无)

  • 在 Outlook 网页版 中,将禁用新邮件、答复和转发的签名选项。 方法也会禁用所选的签名。

  • 在 Android 版和 iOS 版 Outlook 中,将清除移动设备上保存的签名。

getAttachmentContentAsync(attachmentId, options, callback)

从邮件或约会中获取附件,并将其作为 AttachmentContent 对象返回。

方法 getAttachmentContentAsync 从项中获取具有指定标识符的附件。 最佳做法是,应从通话中获取附件的标识符,然后在同一 getAttachmentsAsync 会话中使用该标识符检索附件。 在 Outlook 网页版和移动设备上,附件标识符只在同一个会话中才有效。 当用户关闭应用时,会话结束,或者如果用户开始撰写内联窗体,然后弹出窗体以在单独的窗口中继续。

getAttachmentContentAsync(attachmentId, callback)

从邮件或约会中获取附件,并将其作为 AttachmentContent 对象返回。

方法 getAttachmentContentAsync 从项中获取具有指定标识符的附件。 最佳做法是,应从通话中获取附件的标识符,然后在同一 getAttachmentsAsync 会话中使用该标识符检索附件。 在 Outlook 网页版和移动设备上,附件标识符只在同一个会话中才有效。 当用户关闭应用时,会话结束,或者如果用户开始撰写内联窗体,然后弹出窗体以在单独的窗口中继续。

getAttachmentsAsync(options, callback)

获取项的附件作为数组。

getAttachmentsAsync(callback)

获取项的附件作为数组。

getComposeTypeAsync(options, callback)

指定邮件撰写的类型及其强制类型。 邮件可以是新邮件,也可以是答复或转发。 强制类型可以是 HTML 或纯文本。

getComposeTypeAsync(callback)

指定邮件撰写的类型及其强制类型。 邮件可以是新邮件,也可以是答复或转发。 强制类型可以是 HTML 或纯文本。

getConversationIndexAsync(options, callback)

获取会话线程中当前消息的 Base64 编码位置。

getConversationIndexAsync(callback)

获取会话线程中当前消息的 Base64 编码位置。

getInitializationContextAsync(options, callback)

获取当 加载项被可操作消息激活时传递的初始化数据。

getInitializationContextAsync(callback)

获取当 加载项被可操作消息激活时传递的初始化数据。

getItemClassAsync(options, callback)

获取所选邮件的 Exchange Web Services 项类。

getItemClassAsync(callback)

获取所选邮件的 Exchange Web Services 项类。

getItemIdAsync(options, callback)

异步获取已保存项的 ID。

调用时,此方法通过回调函数返回项 ID。

注意:如果你的外接程序在撰写模式下调用 getItemIdAsync 项目 (例如,若要获取 itemId 与 EWS 或 REST API) 一起使用,请注意,当 Outlook 处于缓存模式时,可能需要一段时间才能将项目同步到服务器。 在项目同步之前, itemId 无法识别,并且使用它将返回错误。

getItemIdAsync(callback)

异步获取已保存项的 ID。

调用时,此方法通过回调函数返回项 ID。

注意:如果你的外接程序在撰写模式下调用 getItemIdAsync 项目 (例如,若要获取 itemId 与 EWS 或 REST API) 一起使用,请注意,当 Outlook 处于缓存模式时,可能需要一段时间才能将项目同步到服务器。 在项目同步之前, itemId 无法识别,并且使用它将返回错误。

getSelectedDataAsync(coercionType, options, callback)

以异步方式返回邮件的主题或正文中选定的数据。

如果没有选择,但光标位于正文或主题中,该方法将返回所选数据的空字符串。 如果选定的是字段,而不是正文或主题,则此方法返回 InvalidSelection 错误。

若要从回调函数访问所选数据,请调用 asyncResult.value.data。 若要访问所选内容来自的源属性,请调用 asyncResult.value.sourceProperty,它将为 bodysubject

getSelectedDataAsync(coercionType, callback)

以异步方式返回邮件的主题或正文中选定的数据。

如果没有选择,但光标位于正文或主题中,该方法将返回所选数据的空字符串。 如果选定的是字段,而不是正文或主题,则此方法返回 InvalidSelection 错误。

若要从回调函数访问所选数据,请调用 asyncResult.value.data。 若要访问所选内容来自的源属性,请调用 asyncResult.value.sourceProperty,它将为 bodysubject

getSharedPropertiesAsync(options, callback)

获取共享文件夹或共享邮箱中约会或邮件的属性。

有关使用此 API 的详细信息,请参阅 在 Outlook 外接程序中启用共享文件夹和共享邮箱方案。

getSharedPropertiesAsync(callback)

获取共享文件夹或共享邮箱中约会或邮件的属性。

有关使用此 API 的详细信息,请参阅 在 Outlook 外接程序中启用共享文件夹和共享邮箱方案。

isClientSignatureEnabledAsync(options, callback)

获取是否启用了客户端签名。

对于 Windows 和 Mac 富客户端,如果新邮件、答复或转发的默认签名设置为发送 Outlook 帐户的模板,则 API 调用应返回 true 。 对于Outlook 网页版,如果为撰写类型 newMail、 或 forward启用了签名,reply则 API 调用应返回 true 。 如果在 Mac 或 Windows 富客户端中将设置设置为“ (无) ”,或者在 Outlook 网页版中禁用,则 API 调用应返回 false

isClientSignatureEnabledAsync(callback)

获取是否启用了客户端签名。

对于 Windows 和 Mac 富客户端,如果新邮件、答复或转发的默认签名设置为发送 Outlook 帐户的模板,则 API 调用应返回 true 。 对于Outlook 网页版,如果为撰写类型 newMail、 或 forward启用了签名,reply则 API 调用应返回 true 。 如果在 Mac 或 Windows 富客户端中将设置设置为“ (无) ”,或者在 Outlook 网页版中禁用,则 API 调用应返回 false

loadCustomPropertiesAsync(callback, userContext)

异步加载所选项目上此外接程序的自定义属性。

自定义属性以键值对的形式存储在每个应用、每个项目的基础上。 此方法在回调中返回 CustomProperties 对象,该对象提供访问特定于当前项和当前加载项的自定义属性的方法。 自定义属性不会对项进行加密,因此不应将其用作安全存储。

自定义属性作为 asyncResult.value 属性中的 CustomProperties 对象提供。 此对象可用于从邮件项获取、设置、保存和删除自定义属性。

removeAttachmentAsync(attachmentId, options, callback)

将附件从邮件或约会中删除。

removeAttachmentAsync 方法删除项目中带指定标识符的附件。 最佳做法是,仅当同一个邮件应用程序在同一会话中添加了一个附件时,你才应使用该附件标识符来删除该附件。 在 Outlook 网页版和移动设备上,附件标识符只在同一个会话中才有效。 当用户关闭应用时,会话结束,或者如果用户开始撰写内联窗体,然后弹出窗体以在单独的窗口中继续。

removeAttachmentAsync(attachmentId, callback)

将附件从邮件或约会中删除。

removeAttachmentAsync 方法删除项目中带指定标识符的附件。 最佳做法是,仅当同一个邮件应用程序在同一会话中添加了一个附件时,你才应使用该附件标识符来删除该附件。 在 Outlook 网页版和移动设备上,附件标识符只在同一个会话中才有效。 当用户关闭应用时,会话结束,或者如果用户开始撰写内联窗体,然后弹出窗体以在单独的窗口中继续。

removeHandlerAsync(eventType, options, callback)

删除受支持事件类型的事件处理程序。 注意:事件仅适用于任务窗格实现。

有关支持的事件,请参阅 Item 对象模型 事件部分

removeHandlerAsync(eventType, callback)

删除受支持事件类型的事件处理程序。 注意:事件仅适用于任务窗格实现。

有关支持的事件,请参阅 Item 对象模型 事件部分

saveAsync(options, callback)

异步将当前消息保存为草稿。

saveAsync(callback)

异步将当前消息保存为草稿。

setSelectedDataAsync(data, options, callback)

以异步方式将数据插入到邮件的正文或主题中。

方法 setSelectedDataAsync 在项目的主题或正文的光标位置插入指定的字符串,或者,如果在编辑器中选择了文本,则替换所选文本。 如果光标不在正文或主题字段中,则返回错误。 插入后,光标将置于插入内容的末尾。

setSelectedDataAsync(data, callback)

以异步方式将数据插入到邮件的正文或主题中。

方法 setSelectedDataAsync 在项目的主题或正文的光标位置插入指定的字符串,或者,如果在编辑器中选择了文本,则替换所选文本。 如果光标不在正文或主题字段中,则返回错误。 插入后,光标将置于插入内容的末尾。

属性详细信息

bcc

获取一个 对象,该对象提供获取或更新密 件抄送 (密件抄 送) 行收件人的方法。

根据客户端/平台 ((即 Windows、Mac 等 ) ),可能会对可以获取或更新的收件人数施加限制。 有关更多详细信息,请参阅 Recipients 对象。

bcc: Recipients;

属性值

注解

[ API set: Mailbox 1.1 ]

最低权限级别读取项

适用的 Outlook 模式:邮件撰写

示例

Office.context.mailbox.item.bcc.setAsync( ['alice@contoso.com', 'bob@contoso.com'] );
Office.context.mailbox.item.bcc.addAsync( ['jason@contoso.com'] );
Office.context.mailbox.item.bcc.getAsync(callback);

function callback(asyncResult) {
    const arrayOfBccRecipients = asyncResult.value;
}
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/30-recipients-and-attendees/get-set-bcc-message-compose.yaml

Office.context.mailbox.item.bcc.getAsync(function(asyncResult) {
  if (asyncResult.status === Office.AsyncResultStatus.Succeeded) {
    const msgBcc = asyncResult.value;
    console.log("Message being blind-copied to:");
    for (let i = 0; i < msgBcc.length; i++) {
      console.log(msgBcc[i].displayName + " (" + msgBcc[i].emailAddress + ")");
    }
  } else {
    console.error(asyncResult.error);
  }
});

...

const email = $("#emailBcc")
  .val()
  .toString();
const emailArray = [email];
Office.context.mailbox.item.bcc.setAsync(emailArray, function(asyncResult) {
  if (asyncResult.status === Office.AsyncResultStatus.Succeeded) {
    console.log("Succeeded in setting Bcc field.");
  } else {
    console.error(asyncResult.error);
  }
});

body

获取一个提供用于处理项目正文的方法的对象。

body: Body;

属性值

注解

[ API set: Mailbox 1.1 ]

最低权限级别读取项

适用的 Outlook 模式:邮件撰写

示例

// This example gets the body of the item as plain text.
Office.context.mailbox.item.body.getAsync(
    "text",
    { asyncContext: "This is passed to the callback" },
    function callback(result) {
        // Do something with the result.
    });

// The following is an example of the result parameter passed to the callback function.
{
    "value": "TEXT of whole body (including threads below)",
    "status": "succeeded",
    "asyncContext": "This is passed to the callback"
}

categories

获取一个 对象,该对象提供用于管理项类别的方法。

重要提示:在 Outlook 网页版 中,不能使用 API 在撰写模式下管理邮件的类别。

categories: Categories;

属性值

注解

[ API set: Mailbox 1.8 ]

最低权限级别读取项

适用的 Outlook 模式:邮件撰写

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/45-categories/work-with-categories.yaml

Office.context.mailbox.item.categories.getAsync(function(asyncResult) {
  if (asyncResult.status === Office.AsyncResultStatus.Succeeded) {
    const categories = asyncResult.value;
    if (categories && categories.length > 0) {
      console.log("Categories assigned to this item:");
      console.log(JSON.stringify(categories));
    } else {
      console.log("There are no categories assigned to this item.");
    }
  } else {
    console.error(asyncResult.error);
  }
});

...

// Note: In order for you to successfully add a category,
// it must be in the mailbox categories master list.

Office.context.mailbox.masterCategories.getAsync(function(asyncResult) {
  if (asyncResult.status === Office.AsyncResultStatus.Succeeded) {
    const masterCategories = asyncResult.value;
    if (masterCategories && masterCategories.length > 0) {
      // Grab the first category from the master list.
      const categoryToAdd = [masterCategories[0].displayName];
      Office.context.mailbox.item.categories.addAsync(categoryToAdd, function(asyncResult) {
        if (asyncResult.status === Office.AsyncResultStatus.Succeeded) {
          console.log(`Successfully assigned category '${categoryToAdd}' to item.`);
        } else {
          console.log("categories.addAsync call failed with error: " + asyncResult.error.message);
        }
      });
    } else {
      console.log("There are no categories in the master list on this mailbox. You can add categories using Office.context.mailbox.masterCategories.addAsync.");
    }
  } else {
    console.error(asyncResult.error);
  }
});

...

Office.context.mailbox.item.categories.getAsync(function(asyncResult) {
  if (asyncResult.status === Office.AsyncResultStatus.Succeeded) {
    const categories = asyncResult.value;
    if (categories && categories.length > 0) {
      // Grab the first category assigned to this item.
      const categoryToRemove = [categories[0].displayName];
      Office.context.mailbox.item.categories.removeAsync(categoryToRemove, function(asyncResult) {
        if (asyncResult.status === Office.AsyncResultStatus.Succeeded) {
          console.log(`Successfully unassigned category '${categoryToRemove}' from this item.`);
        } else {
          console.log("categories.removeAsync call failed with error: " + asyncResult.error.message);
        }
      });
    } else {
      console.log("There are no categories assigned to this item.");
    }
  } else {
    console.error(asyncResult.error);
  }
});

cc

提供对邮件的抄送 (Cc) 收件人的访问权限。 对象的类型和访问级别取决于当前项的模式。

cc 属性返回一个 Recipients 对象,该对象提供用于获取或更新邮件的“抄送”行上收件人的方法。 但是,根据客户端/平台 ((即 Windows、Mac 等 ) ),可能会对可以获取或更新的收件人数施加限制。 有关更多详细信息,请参阅 Recipients 对象。

cc: Recipients;

属性值

注解

最低权限级别读取项

适用的 Outlook 模式:邮件撰写

示例

Office.context.mailbox.item.cc.setAsync( ['alice@contoso.com', 'bob@contoso.com'] );
Office.context.mailbox.item.cc.addAsync( ['jason@contoso.com'] );
Office.context.mailbox.item.cc.getAsync(callback);

function callback(asyncResult) {
    const arrayOfCcRecipients = asyncResult.value;
}
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/30-recipients-and-attendees/get-set-cc-message-compose.yaml

Office.context.mailbox.item.cc.getAsync(function(asyncResult) {
  if (asyncResult.status === Office.AsyncResultStatus.Succeeded) {
    const msgCc = asyncResult.value;
    console.log("Message being copied to:");
    for (let i = 0; i < msgCc.length; i++) {
      console.log(msgCc[i].displayName + " (" + msgCc[i].emailAddress + ")");
    }
  } else {
    console.error(asyncResult.error);
  }
});

...

const email = $("#emailCc")
  .val()
  .toString();
const emailArray = [email];
Office.context.mailbox.item.cc.setAsync(emailArray, function(asyncResult) {
  if (asyncResult.status === Office.AsyncResultStatus.Succeeded) {
    console.log("Succeeded in setting Cc field.");
  } else {
    console.error(asyncResult.error);
  }
});

conversationId

获取包含特定消息的电子邮件会话的标识符。

如果在阅读窗体或撰写窗体的回复中激活邮件应用程序,则此属性可以获得一个整数值。 如果用户随后更改了回复邮件的主题(若发送回复),则该邮件的对话 ID 将改变且之前获取的值将不适用。

对于撰写窗体的新项目,此属性获得一个 null 值。 如果用户设置一个主题并保存该项目,conversationId 属性将返回一个值。

conversationId: string;

属性值

string

注解

最低权限级别读取项

适用的 Outlook 模式:邮件撰写

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/90-other-item-apis/get-conversation-id-message.yaml

console.log(`Conversation ID: ${Office.context.mailbox.item.conversationId}`);

delayDeliveryTime

获取或设置邮件的延迟传递日期和时间。

属性 delayDeliveryTime 返回一个 DelayDeliveryTime 对象,该对象提供用于管理邮件传递日期和时间的方法。

delayDeliveryTime: DelayDeliveryTime;

属性值

注解

[ API set: Mailbox 1.13 ]

最低权限级别读取项

适用的 Outlook 模式:邮件撰写

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/90-other-item-apis/delay-message-delivery.yaml

function setDeliveryDate(minutes) {
  // This snippet sets the delivery date and time of a message.
  const currentTime = new Date().getTime();
  const milliseconds = totalDelay * 60000;
  const timeDelay = new Date(currentTime + milliseconds);
  Office.context.mailbox.item.delayDeliveryTime.setAsync(timeDelay, (asyncResult) => {
    if (asyncResult.status === Office.AsyncResultStatus.Failed) {
      console.log(asyncResult.error.message);
      return;
    }

    if (minutes === 1440) {
      console.log(`Delayed delivery by an additional one day.`);
    } else {
      console.log(`Delayed delivery by an additional ${minutes} minutes.`);
    }
  });
}

from

获取邮件发件人的电子邮件地址。

属性 from 返回一个 From 对象,该对象提供从值获取 的方法。

from: From;

属性值

注解

[ API set: Mailbox 1.7 ]

最低权限级别读取项

适用的 Outlook 模式:邮件撰写

重要提示:Android 版和 iOS 版 Outlook 支持此属性。 有关示例方案,请参阅 在 Outlook 移动加载项中实现基于事件的激活。

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/30-recipients-and-attendees/get-from-message-compose.yaml

Office.context.mailbox.item.from.getAsync(function(asyncResult) {
  if (asyncResult.status === Office.AsyncResultStatus.Succeeded) {
    const msgFrom = asyncResult.value;
    console.log("Message from: " + msgFrom.displayName + " (" + msgFrom.emailAddress + ")");
  } else {
    console.error(asyncResult.error);
  }
});

inReplyTo

注意

此 API 以预览状态提供给开发者,可能根据我们收到的反馈更改。 请勿在生产环境中使用此 API。

获取当前消息答复的原始消息的消息 ID。

inReplyTo: string;

属性值

string

注解

[ API 集:邮箱预览 ]

最低权限级别读取项

适用的 Outlook 模式:邮件撰写

重要说明

  • 若要预览 inReplyTo 属性,必须安装 Outlook on Windows 版本 2402 (内部版本 17317.20000) 或更高版本。 然后,加入 Microsoft 365 预览体验计划 ,并选择 “Beta 频道” 选项以访问 Office beta 版本。

  • 在 Outlook on Windows 中, inReplyTo 无论用户做出何种更改(例如更改答复中的主题)都会在所有答复中保留该值。

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/99-preview-apis/get-in-reply-to.yaml

// This snippet gets the ID of the message being replied to by the current message (PR_IN_REPLY_TO_ID).
// The API call is supported on messages being composed and isn't supported on read items.
const inReplyTo = Office.context.mailbox.item.inReplyTo;
if (inReplyTo) {
  console.log("ID of the message being replied to: " + inReplyTo);
} else {
  console.log("No InReplyTo property available for this message");
}

internetHeaders

获取或设置消息的自定义 Internet 标头。

属性 internetHeaders 返回一个 InternetHeaders 对象,该对象提供管理消息上的 Internet 标头的方法。

若要了解详细信息,请参阅在 Outlook 外接程序中获取和设置邮件的 Internet 标头

internetHeaders: InternetHeaders;

属性值

注解

[ API set: Mailbox 1.8 ]

最低权限级别读取项

适用的 Outlook 模式:邮件撰写

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/70-mime-headers/manage-custom-internet-headers-message-compose.yaml

Office.context.mailbox.item.internetHeaders.getAsync(
  ["preferred-fruit", "preferred-vegetable", "best-vegetable", "nonexistent-header"],
  function (asyncResult) {
    if (asyncResult.status === Office.AsyncResultStatus.Succeeded) {
      console.log("Selected headers: " + JSON.stringify(asyncResult.value));
    } else {
      console.log("Error getting selected headers: " + JSON.stringify(asyncResult.error));
    }
  }
);

itemType

获取实例表示的项的类型。

属性 itemType 返回枚举值之 ItemType 一,指示项目对象实例是消息还是约会。

itemType: MailboxEnums.ItemType | string;

属性值

注解

最低权限级别读取项

适用的 Outlook 模式:邮件撰写

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/90-other-item-apis/get-item-type.yaml

const itemType = Office.context.mailbox.item.itemType;
switch (itemType) {
    case Office.MailboxEnums.ItemType.Appointment:
        console.log(`Current item is an ${itemType}.`);
        break;
    case Office.MailboxEnums.ItemType.Message:
        console.log(`Current item is a ${itemType}. A message could be an email, meeting request, meeting response, or meeting cancellation.`);
        break;
}

notificationMessages

获取项目的通知邮件。

notificationMessages: NotificationMessages;

属性值

注解

[ 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

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

...

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

...

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

...

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

sensitivityLabel

获取要获取或设置消息 的敏感度标签 的对象。

sensitivityLabel: SensitivityLabel;

属性值

注解

[ API set: Mailbox 1.13 ]

最低权限级别读/写项

适用的 Outlook 模式:邮件撰写

重要提示:若要在外接程序中使用敏感度标签功能,必须具有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);
  }
});

seriesId

获取实例所属的序列的 ID。

在 Outlook 网页版 和桌面客户端中, seriesId 返回此项所属的父 (系列) 项的 Exchange Web Services (EWS) ID。 但是,在 iOS 和 Android 上,seriesId 返回父项的 REST ID。

注意:属性返回的 seriesId 标识符与 Exchange Web Services 项标识符相同。 属性 seriesId 与 Outlook REST API 使用的 Outlook ID 不同。 在使用此值进行 REST API 调用之前,应使用 Office.context.mailbox.convertToRestId进行转换。 有关详细信息,请参阅 使用 Outlook 外接程序中的 Outlook REST API。

对于没有父项(如单个约会、系列项目或会议请求)的项目,属性seriesIdnull返回 ,对于不是会议请求的任何其他项目,则返回 undefined

seriesId: string;

属性值

string

注解

[ API set: Mailbox 1.7 ]

最低权限级别读取项

适用的 Outlook 模式:邮件撰写

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/50-recurrence/get-series-id.yaml

const seriesId = Office.context.mailbox.item.seriesId;

if (seriesId === undefined) {
  console.log("This is a message that's not a meeting request.");
} else if (seriesId === null) {
  console.log("This is a single appointment, a parent series, or a meeting request for a series or single meeting.");
} else {
  console.log("This is an instance belonging to series with ID " + seriesId);
}

sessionData

在撰写模式下管理项目的 SessionData

重要提示:每个外接程序的整个 SessionData 对象限制为 50,000 个字符。

sessionData: SessionData;

属性值

注解

[ API set: Mailbox 1.11 ]

最低权限级别读取项

适用的 Outlook 模式:邮件撰写

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/90-other-item-apis/session-data-apis.yaml

Office.context.mailbox.item.sessionData.getAllAsync(function(asyncResult) {
  if (asyncResult.status === Office.AsyncResultStatus.Succeeded) {
    console.log("The sessionData is " + JSON.stringify(asyncResult.value));
  } else {
    console.log("Failed to get all sessionData. Error: " + JSON.stringify(asyncResult.error));
  }
});

subject

获取或设置显示在项目的主题字段中的说明。

subject 属性获取或设置由电子邮件服务器发送项目时的整个主题。

subject 属性返回一个 Subject 对象,该对象提供用于获取和设置主题的方法。

subject: Subject;

属性值

注解

最低权限级别读取项

适用的 Outlook 模式:邮件撰写

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/90-other-item-apis/get-set-subject-compose.yaml

Office.context.mailbox.item.subject.getAsync((result) => {
  if (result.status !== Office.AsyncResultStatus.Succeeded) {
    console.error(`Action failed with message ${result.error.message}`);
    return;
  }
  console.log(`Subject: ${result.value}`);
});

...

let subject = "Hello World!";
Office.context.mailbox.item.subject.setAsync(subject, (result) => {
  if (result.status !== Office.AsyncResultStatus.Succeeded) {
    console.error(`Action failed with message ${result.error.message}`);
    return;
  }
  console.log(`Successfully set subject to ${subject}`);
});

to

提供对邮件的“收件人”行上的收件人的访问权限。 对象的类型和访问级别取决于当前项的模式。

to 属性返回一个 Recipients 对象,该对象提供用于获取或更新邮件的“收件人”行上收件人的方法。 但是,根据客户端/平台 ((即 Windows、Mac 等 ) ),可能会对可以获取或更新的收件人数施加限制。 有关更多详细信息,请参阅 Recipients 对象。

to: Recipients;

属性值

注解

最低权限级别读取项

适用的 Outlook 模式:邮件撰写

示例

Office.context.mailbox.item.to.setAsync( ['alice@contoso.com', 'bob@contoso.com'] );
Office.context.mailbox.item.to.addAsync( ['jason@contoso.com'] );
Office.context.mailbox.item.to.getAsync(callback);

function callback(asyncResult) {
    const arrayOfToRecipients = asyncResult.value;
}
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/30-recipients-and-attendees/get-set-to-message-compose.yaml

Office.context.mailbox.item.to.getAsync(function(asyncResult) {
  if (asyncResult.status === Office.AsyncResultStatus.Succeeded) {
    const msgTo = asyncResult.value;
    console.log("Message being sent to:");
    for (let i = 0; i < msgTo.length; i++) {
      console.log(msgTo[i].displayName + " (" + msgTo[i].emailAddress + ")");
    }
  } else {
    console.error(asyncResult.error);
  }
});

...

const email = $("#emailTo")
  .val()
  .toString();
const emailArray = [email];
Office.context.mailbox.item.to.setAsync(emailArray, function(asyncResult) {
  if (asyncResult.status === Office.AsyncResultStatus.Succeeded) {
    console.log("Succeeded in setting To field.");
  } else {
    console.error(asyncResult.error);
  }
});

方法详细信息

addFileAttachmentAsync(uri, attachmentName, options, callback)

将文件作为附件添加到邮件或约会。

addFileAttachmentAsync 方法在指定的 URI 上载文件并将其附加到撰写窗体中的项目。

随后可以将该标识符与 removeAttachmentAsync 方法一同使用,以删除同一个会话中的附件。

重要提示:在 Windows 版 Outlook 的最新版本中,引入了一个 Authorization: Bearer bug,错误地将标头追加到此操作 (无论是使用此 API 还是 Outlook UI) 。 若要解决此问题,可以尝试使用要求集 1.8 中引入的 addFileAttachmentFromBase64 API。

addFileAttachmentAsync(uri: string, attachmentName: string, options: Office.AsyncContextOptions & { isInline: boolean }, callback?: (asyncResult: Office.AsyncResult<string>) => void): void;

参数

uri

string

提供附加到邮件或约会的文件的位置的 URI。 最大长度为 2048 个字符。

attachmentName

string

在附件上载过程中显示的附件名称。 最大长度为 255 个字符。

options

Office.AsyncContextOptions & { isInline: boolean }

包含以下一个或多个属性的对象文本:- asyncContext:开发人员可以在回调函数中提供他们想要访问的任何对象。 isInline:如果为 true,则表示附件将以内联方式显示在邮件正文中,不应显示在附件列表中。

callback

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

可选。 方法完成后,使用类型的Office.AsyncResult单个参数调用在 参数中callback传递的函数。 如果成功,附件标识符将在 asyncResult.value 属性中提供。 如果上传附件失败,asyncResult 对象将包含一个提供错误说明的 Error 对象。

返回

void

注解

[ API set: Mailbox 1.1 ]

最低权限级别读/写项

适用的 Outlook 模式:邮件撰写

错误

  • AttachmentSizeExceeded:附件大于允许的大小。

  • FileTypeNotSupported:附件具有不允许的扩展名。

  • NumberOfAttachmentsExceeded:邮件或约会的附件过多。

示例

function callback(result) {
    if (result.error) {
        console.log(result.error);
    } else {
        console.log("Attachment added");
    }
}

function addAttachment() {
    // The values in asyncContext can be accessed in the callback.
    const options = { 'asyncContext': { var1: 1, var2: 2 } };

    const attachmentURL = "https://contoso.com/rtm/icon.png";
    Office.context.mailbox.item.addFileAttachmentAsync(attachmentURL, attachmentURL, options, callback);
}
// The following example adds an image file as an inline attachment and
// references the attachment in the message body.
Office.context.mailbox.item.addFileAttachmentAsync(
    "http://i.imgur.com/WJXklif.png",
    "cute_bird.png",
    {
        isInline: true
    },
    function (asyncResult) {
        Office.context.mailbox.item.body.setAsync(
            "<p>Here's a cute bird!</p><img src='cid:cute_bird.png'>",
            {
                "coercionType": "html"
            },
            function (asyncResult) {
                // Do something here.
            });
    });
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/40-attachments/attachments-compose.yaml

const attachmentUrl = $("#attachmentUrl").val();
Office.context.mailbox.item.addFileAttachmentAsync(
    attachmentUrl,
    getFileName(attachmentUrl),
    { "asyncContext" : { var1: 1, var2: true } },
    function(result) { console.log(result); });

addFileAttachmentAsync(uri, attachmentName, callback)

将文件作为附件添加到邮件或约会。

addFileAttachmentAsync 方法在指定的 URI 上载文件并将其附加到撰写窗体中的项目。

随后可以将该标识符与 removeAttachmentAsync 方法一同使用,以删除同一个会话中的附件。

重要提示:在 Windows 版 Outlook 的最新版本中,引入了一个 Authorization: Bearer bug,错误地将标头追加到此操作 (无论是使用此 API 还是 Outlook UI) 。 若要解决此问题,可以尝试使用要求集 1.8 中引入的 addFileAttachmentFromBase64 API。

addFileAttachmentAsync(uri: string, attachmentName: string, callback?: (asyncResult: Office.AsyncResult<string>) => void): void;

参数

uri

string

提供附加到邮件或约会的文件的位置的 URI。 最大长度为 2048 个字符。

attachmentName

string

在附件上载过程中显示的附件名称。 最大长度为 255 个字符。

callback

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

可选。 方法完成后,使用类型的Office.AsyncResult单个参数调用在 参数中callback传递的函数。 如果成功,附件标识符将在 asyncResult.value 属性中提供。 如果上传附件失败,asyncResult 对象将包含一个提供错误说明的 Error 对象。

返回

void

注解

[ API set: Mailbox 1.1 ]

最低权限级别读/写项

适用的 Outlook 模式:邮件撰写

错误

  • AttachmentSizeExceeded:附件大于允许的大小。

  • FileTypeNotSupported:附件具有不允许的扩展名。

  • NumberOfAttachmentsExceeded:邮件或约会的附件过多。

addFileAttachmentFromBase64Async(base64File, attachmentName, options, callback)

将文件作为附件添加到邮件或约会。

方法 addFileAttachmentFromBase64Async 从 Base64 编码上传文件,并将其附加到撰写窗体中的项目。 此方法返回 对象中的 asyncResult.value 附件标识符。

随后可以将该标识符与 removeAttachmentAsync 方法一同使用,以删除同一个会话中的附件。

addFileAttachmentFromBase64Async(base64File: string, attachmentName: string, options: Office.AsyncContextOptions & { isInline: boolean }, callback?: (asyncResult: Office.AsyncResult<string>) => void): void;

参数

base64File

string

要添加到电子邮件或事件的图像或文件的 Base64 编码内容。 编码字符串的最大长度为 27,892,122 个字符, (大约 25 MB) 。

attachmentName

string

在附件上载过程中显示的附件名称。 最大长度为 255 个字符。

options

Office.AsyncContextOptions & { isInline: boolean }

包含以下一个或多个属性的对象文本:- asyncContext:开发人员可以在回调函数中提供他们想要访问的任何对象。 isInline:如果为 true,则指示附件将以内联方式显示在邮件正文中,并且不应显示在附件列表中。

callback

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

可选。 方法完成后,使用 Office.AsyncResult 类型的单个参数调用在 参数中 callback 传递的函数。 如果成功,附件标识符将在 asyncResult.value 属性中提供。 如果上传附件失败,asyncResult 对象将包含一个提供错误说明的 Error 对象。

返回

void

注解

[ API set: Mailbox 1.8 ]

最低权限级别读/写项

适用的 Outlook 模式:邮件撰写

重要说明

  • Android 版和 iOS 版 Outlook 支持在撰写模式下将内联 Base64 文件添加到邮件。 有关 Outlook mobile 中支持的 API 的详细信息,请参阅移动设备上的 Outlook 中支持的 Outlook JavaScript API

  • 如果使用数据 URL API (例如 readAsDataURL) ,则需要去除数据 URL 前缀,然后将字符串的其余部分发送到此 API。 例如,如果完整字符串由 data:image/svg+xml;base64,<rest of Base64 string>表示,则删除 data:image/svg+xml;base64,

  • 如果要将内联 Base64 图像添加到正在撰写的邮件或约会的正文中,必须先使用 Office.context.mailbox.item.body.getAsync 方法获取当前项目正文,然后使用 插入图像 addFileAttachmentFromBase64Async。 否则,图像在插入后不会呈现在正文中。 有关进一步的指导,请参阅 附加文件

错误

  • AttachmentSizeExceeded:附件大于允许的大小。

  • FileTypeNotSupported:附件具有不允许的扩展名。

  • NumberOfAttachmentsExceeded:邮件或约会的附件过多。

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/40-attachments/attachments-compose.yaml

base64String = "iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAACXBIWXMAAAsSAAALEgHS3X78AAACRUlEQVRYw82XzXHbMBCFP2F8tzsQc8Ixyh0zoiuIXIGdCsxUYKqC0B04FdiuwMoM7mGOOIXqQGoAymXhgSX+itJM9kIRFLAP+3YXD5Pdbscx5oxaAIW8Ztr6l2PWmQwF4IyaieP53qdfAqQ8CwBn1JU4vpWhrbxXQA5MZfynANmcDIAzKgcy4FKGXsVJFf3nLgKyBQptfT4KQMRz2N0fcbxqmRMDWXflx0VPnrdArq0vekQ1Dv0UeHZGNebHhwjU8AzwKM43RyZnbAf58Q6ghudeWd0Aus0+5EcMIIRi3beua0D3Nm39BEAx3i7HTK4DEBJn5YxKOnaRA5+ErpMBWMpzDvx1RuXCcxOISlufAjfC7zgAsqsvUvMAD0ApPaEtGi9AIlUzKgJo60tt/SyKRkzLrAXERluf7W1gOICWaMyB386oooOWsIHvXbSoHuUSFovtHqicUVnH3EJoeT0aQEf5/XBGlc6otIOWBXAtPeZkAIJ9Bt6cUU9tZautX2nrk3MACHYr1ZKProKRtDw4o8pzAPjWo+NtpXTTvoteDDg8noDAcwbcRedAkGdFXyk2GEDcegVAFp2gyVDHjRQ4o6q2smoqtR5Hd+qMqtoALCWUUymr1m43QMZfOaMK4C0SrMsDANJ2E5FNcbdbjHC+ENl+H0myJFbLtaq4Rt8dyPBYRQV1E40nMv9rl7xrOw3DGb+Whcqu3i/OM6CUOWvgRlufNmnLYy4m77uJI7AXtdNcTDrU71LEyv7v01/N/ovL6bmu5/8A1tNWZldH0W4AAAAASUVORK5CYII=";
Office.context.mailbox.item.addFileAttachmentFromBase64Async(
    base64String,
    "logo.png",
    { isInline: false },
    function(result) { console.log(result); });

...

// Set the signature for the current item with inline image.
const modIcon1Base64 = "iVBORw0KGgoAAAANSUhEUgAAABwAAAAcCAYAAAByDd+UAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA2ZpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYxIDY0LjE0MDk0OSwgMjAxMC8xMi8wNy0xMDo1NzowMSAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtcE1NOk9yaWdpbmFsRG9jdW1lbnRJRD0ieG1wLmRpZDpDRDMxMDg1MjBCNDZFMTExODE2MkM1RUI2M0M4MDYxRCIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDpFMTUxQjgyRjQ2MEQxMUUxODlFMkQwNTYzQ0YwMTUxMiIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDpFMTUxQjgyRTQ2MEQxMUUxODlFMkQwNTYzQ0YwMTUxMiIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgQ1M1LjEgV2luZG93cyI+IDx4bXBNTTpEZXJpdmVkRnJvbSBzdFJlZjppbnN0YW5jZUlEPSJ4bXAuaWlkOkQxMzEwODUyMEI0NkUxMTE4MTYyQzVFQjYzQzgwNjFEIiBzdFJlZjpkb2N1bWVudElEPSJ4bXAuZGlkOkNEMzEwODUyMEI0NkUxMTE4MTYyQzVFQjYzQzgwNjFEIi8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+uC/WfAAAAehJREFUeNpilCzfwEAEkAbiECA2A2J1IOaHin8E4ptAfBaIVwLxU0IGMRKw0B6IW4DYhoE4cASIK6E0VsCEQ1wUiNcB8QESLGOAqj0MxBuhZhBloS4QnwHiQAbygR/UDF1CFupCXSjHQDmQg5qli8tCUBBsQUoQ1AD8UDNFsVk4n0o+w+bT+egWglKjNymmeGhLkqLcG2oHAwtUoIuQDj5OVgZPLUmwRe5aEmAxqYqNpFgKssOcCeplM0KqdST5GfpDDRm0JfkYrj3/SE7QguyQY4ImYYLgCtAS10kHGMw6dzNsv/qC7OwCClJXYlR++v6b4er3j5QmIFcmaNlIL6AOslCIjhYKMTHQGTBBqxh6gXcgC6/R0cKbIAv30dHCfaAKGJTxHxJSqS3Fz9DkowNmywpyMcgA8fF7b8D8VWcfM6w8+4gYC+VB+RCk8hSh0gaUD4/dewvlvUWRe/z+GzGWgex4BGtiOAHxXhoHpzMoSGHZAhSPW2lo2VZYWkHOh4nEtLrIAE+hZmNUwK+B2BOIv1PRsu9QM1/jatNcBtVZ0IREKXgENesyoVYbzNIdFFi2A5tl+NqlL6BB4QBNzsSCU1A9nlAzMAALAQMOQl0qB23qWwKxIlIrDBQ394H4OBCvISYqAAIMACVibHDqsO7zAAAAAElFTkSuQmCC";
Office.context.mailbox.item.addFileAttachmentFromBase64Async(
  modIcon1Base64,
  "myImage.png",
  { isInline: true },
  function(result) {
    if (result.status == Office.AsyncResultStatus.Succeeded) {
      const signature = $("#signature").val() + "<img src='cid:myImage.png'>";
      console.log(`Setting signature to "${signature}".`);
      Office.context.mailbox.item.body.setSignatureAsync(
        signature,
        { coercionType: "html" },
        function(asyncResult) {
          console.log(`setSignatureAsync: ${asyncResult.status}`);
        }
      );
    } else {
      console.error(`addFileAttachmentFromBase64Async: ${result.error}`);
    }
  }
);

addFileAttachmentFromBase64Async(base64File, attachmentName, callback)

将文件作为附件添加到邮件或约会。

方法 addFileAttachmentFromBase64Async 从 Base64 编码上传文件,并将其附加到撰写窗体中的项目。 此方法返回 对象中的 asyncResult.value 附件标识符。

随后可以将该标识符与 removeAttachmentAsync 方法一同使用,以删除同一个会话中的附件。

addFileAttachmentFromBase64Async(base64File: string, attachmentName: string, callback?: (asyncResult: Office.AsyncResult<string>) => void): void;

参数

base64File

string

要添加到电子邮件或事件的图像或文件的 Base64 编码内容。 编码字符串的最大长度为 27,892,122 个字符, (大约 25 MB) 。

attachmentName

string

在附件上载过程中显示的附件名称。 最大长度为 255 个字符。

callback

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

可选。 方法完成后,使用 Office.AsyncResult 类型的单个参数调用在 参数中 callback 传递的函数。 如果成功,附件标识符将在 asyncResult.value 属性中提供。 如果上传附件失败,asyncResult 对象将包含一个提供错误说明的 Error 对象。

返回

void

注解

[ API set: Mailbox 1.8 ]

最低权限级别读/写项

适用的 Outlook 模式:邮件撰写

重要说明

  • Android 版和 iOS 版 Outlook 支持在撰写模式下将内联 Base64 文件添加到邮件。 有关 Outlook mobile 中支持的 API 的详细信息,请参阅移动设备上的 Outlook 中支持的 Outlook JavaScript API

  • 如果使用数据 URL API (例如 readAsDataURL) ,则需要去除数据 URL 前缀,然后将字符串的其余部分发送到此 API。 例如,如果完整字符串由 data:image/svg+xml;base64,<rest of Base64 string>表示,则删除 data:image/svg+xml;base64,

  • 如果要将内联 Base64 图像添加到正在撰写的邮件或约会的正文中,必须先使用 Office.context.mailbox.item.body.getAsync 方法获取当前项目正文,然后使用 插入图像 addFileAttachmentFromBase64Async。 否则,图像在插入后不会呈现在正文中。 有关进一步的指导,请参阅 附加文件

错误

  • AttachmentSizeExceeded:附件大于允许的大小。

  • FileTypeNotSupported:附件具有不允许的扩展名。

  • NumberOfAttachmentsExceeded:邮件或约会的附件过多。

addHandlerAsync(eventType, handler, options, callback)

添加支持事件的事件处理程序。 注意:事件仅适用于任务窗格实现。

有关支持的事件,请参阅 Item 对象模型 事件部分

addHandlerAsync(eventType: Office.EventType | string, handler: any, options: Office.AsyncContextOptions, callback?: (asyncResult: Office.AsyncResult<void>) => void): void;

参数

eventType

Office.EventType | string

应调用处理程序的事件。

handler

any

用于处理事件的函数。 此函数必须接受一个参数,即对象文本。 参数type上的 属性将与传递给 addHandlerAsync的参数匹配eventType

options
Office.AsyncContextOptions

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

callback

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

可选。 方法完成后,使用单个参数 asyncResult(即 Office.AsyncResult 对象)调用在 参数中callback传递的函数。

返回

void

注解

[ API set: Mailbox 1.7 ]

最低权限级别读取项

适用的 Outlook 模式:邮件撰写

示例

function myHandlerFunction(eventarg) {
    if (eventarg.attachmentStatus === Office.MailboxEnums.AttachmentStatus.Added) {
        const attachment = eventarg.attachmentDetails;
        console.log("Event Fired and Attachment Added!");
        getAttachmentContentAsync(attachment.id, options, callback);
    }
}

Office.context.mailbox.item.addHandlerAsync(Office.EventType.AttachmentsChanged, myHandlerFunction, myCallback);

addHandlerAsync(eventType, handler, callback)

添加支持事件的事件处理程序。 注意:事件仅适用于任务窗格实现。

有关支持的事件,请参阅 Item 对象模型 事件部分

addHandlerAsync(eventType: Office.EventType | string, handler: any, callback?: (asyncResult: Office.AsyncResult<void>) => void): void;

参数

eventType

Office.EventType | string

应调用处理程序的事件。

handler

any

用于处理事件的函数。 此函数必须接受一个参数,即对象文本。 参数type上的 属性将与传递给 addHandlerAsync的参数匹配eventType

callback

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

可选。 方法完成后,使用单个参数 asyncResult(即 Office.AsyncResult 对象)调用在 参数中callback传递的函数。

返回

void

注解

[ API set: Mailbox 1.7 ]

最低权限级别读取项

适用的 Outlook 模式:邮件撰写

addItemAttachmentAsync(itemId, attachmentName, options, callback)

将 Exchange 项目(如邮件)作为附件添加到邮件或约会。

addItemAttachmentAsync 方法将包含指定 Exchange 标识符的项目附加到撰写窗体中的项目。 如果指定回调函数,则会使用一个参数调用 方法, asyncResult该参数包含附件标识符或指示附加项时发生的任何错误的代码。 如果需要,可以使用 options 参数将状态信息传递给回调函数。

随后可以将该标识符与 removeAttachmentAsync 方法一同使用,以删除同一个会话中的附件。

如果 Office 加载项是在 Outlook 网页版中运行,addItemAttachmentAsync 方法可以将项附加到除正在编辑的项外的项;但既不支持也不建议这样做。

addItemAttachmentAsync(itemId: any, attachmentName: string, options: Office.AsyncContextOptions, callback?: (asyncResult: Office.AsyncResult<string>) => void): void;

参数

itemId

any

要附加的项目的 Exchange 标识符。 最大长度为 100 个字符。

attachmentName

string

在附件上载过程中显示的附件名称。 最大长度为 255 个字符。

options
Office.AsyncContextOptions

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

callback

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

可选。 方法完成后,使用类型的Office.AsyncResult单个参数调用在 参数中callback传递的函数。 如果成功,附件标识符将在 asyncResult.value 属性中提供。 如果添加附件失败,asyncResult 对象将包含一个提供错误说明的 Error 对象。

返回

void

注解

[ API set: Mailbox 1.1 ]

最低权限级别读/写项

适用的 Outlook 模式:邮件撰写

错误

  • NumberOfAttachmentsExceeded:邮件或约会的附件过多。

示例

// The following example adds an existing Outlook item as an attachment
// with the name `My Attachment`.
function callback(result) {
    if (result.error) {
        console.log(result.error);
    } else {
        console.log("Attachment added");
    }
}

function addAttachment() {
    // EWS ID of item to attach (shortened for readability).
    const itemId = "AAMkADI1...AAA=";

    // The values in asyncContext can be accessed in the callback.
    const options = { 'asyncContext': { var1: 1, var2: 2 } };

    Office.context.mailbox.item.addItemAttachmentAsync(itemId, "My Attachment", options, callback);
}
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/40-attachments/attachments-compose.yaml

const attachmentItemId = $("#attachmentItemId").val();
Office.context.mailbox.item.addItemAttachmentAsync(
    attachmentItemId,
    "My attachment",
    { "asyncContext" : { var3: 3, var4: false } },
    function(result) { console.log(result); });

addItemAttachmentAsync(itemId, attachmentName, callback)

将 Exchange 项目(如邮件)作为附件添加到邮件或约会。

addItemAttachmentAsync 方法将包含指定 Exchange 标识符的项目附加到撰写窗体中的项目。 如果指定回调函数,则会使用一个参数调用 方法, asyncResult该参数包含附件标识符或指示附加项时发生的任何错误的代码。 如果需要,可以使用 options 参数将状态信息传递给回调函数。

随后可以将该标识符与 removeAttachmentAsync 方法一同使用,以删除同一个会话中的附件。

如果 Office 加载项是在 Outlook 网页版中运行,addItemAttachmentAsync 方法可以将项附加到除正在编辑的项外的项;但既不支持也不建议这样做。

addItemAttachmentAsync(itemId: any, attachmentName: string, callback?: (asyncResult: Office.AsyncResult<string>) => void): void;

参数

itemId

any

要附加的项目的 Exchange 标识符。 最大长度为 100 个字符。

attachmentName

string

在附件上载过程中显示的附件名称。 最大长度为 255 个字符。

callback

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

可选。 方法完成后,使用类型的Office.AsyncResult单个参数调用在 参数中callback传递的函数。 如果成功,附件标识符将在 asyncResult.value 属性中提供。 如果添加附件失败,asyncResult 对象将包含一个提供错误说明的 Error 对象。

返回

void

注解

[ API set: Mailbox 1.1 ]

最低权限级别读/写项

适用的 Outlook 模式:邮件撰写

错误

  • NumberOfAttachmentsExceeded:邮件或约会的附件过多。

close()

关闭当前正在撰写的项目。

close 方法的行为取决于要撰写的项目的当前状态。 如果项有未保存的更改,客户端会提示用户保存、放弃或关闭操作。

在 Outlook 桌面客户端中 close , 方法对阅读窗格中的答复没有影响。

close(): void;

返回

void

注解

[ API 集:邮箱 1.3 ]

最低权限级别受限

适用的 Outlook 模式:邮件撰写

重要提示:在Outlook 网页版中,如果项目是约会,并且以前使用 saveAsync保存过,则即使自上次保存项目以来未发生任何更改,也会提示用户保存、放弃或取消。

提示close如果希望外接程序:

  • 自动放弃正在撰写的消息,而不会提示用户使用保存对话框。

  • 确定用户何时取消正在撰写的邮件上的保存项目对话框。

  • 关闭阅读窗格中的答复或 Outlook 桌面客户端中的现有草稿。

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/25-item-save-and-close/close.yaml

Office.context.mailbox.item.close();

closeAsync(options, callback)

注意

此 API 以预览状态提供给开发者,可能根据我们收到的反馈更改。 请勿在生产环境中使用此 API。

使用 放弃未保存的更改的选项关闭正在撰写的当前消息。 正在撰写的邮件可以是新邮件、答复或现有草稿。

closeAsync(options: Office.AsyncContextOptions & { discardItem: boolean }, callback?: (asyncResult: Office.AsyncResult<void>) => void): void;

参数

options

Office.AsyncContextOptions & { discardItem: boolean }

包含以下一个或多个属性的对象文本:- asyncContext:开发人员可以在回调函数中提供他们想要访问的任何对象。 discardItem:如果 true为 ,则关闭正在撰写的当前消息,并丢弃未保存的更改。 当参数未声明或未设置为 false时,将显示一个保存对话框,提示用户保存草稿、放弃更改或取消操作。 对于从阅读窗格弹出的新邮件和答复,会出现此行为。 如果要关闭阅读窗格或现有草稿中的回复,必须将 设置为 discardItemtrue。 否则,调用将返回错误。 有关错误的详细信息,请参阅“备注”部分。

callback

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

可选。 方法完成后,使用单个参数 asyncResult(即 Office.AsyncResult 对象)调用在回调参数中传递的函数。

返回

void

注解

[ API 集:邮箱预览 ]

最低权限级别读/写项

适用的 Outlook 模式:邮件撰写

重要提示:该方法 closeAsync 处于预览阶段。 目前仅在 Outlook on Windows 中受支持。

错误

  • The operation was cancelled by the user:用户从保存对话框中选择“ 取消 ”, discardItem 并且 属性未定义或设置为 false

  • The operation is not supported:方法 closeAsync 尝试关闭阅读窗格或现有草稿中的回复, discardItem 并且属性未定义或设置为 false

closeAsync(callback)

注意

此 API 以预览状态提供给开发者,可能根据我们收到的反馈更改。 请勿在生产环境中使用此 API。

关闭正在撰写的当前新邮件。

撰写的新邮件的行为取决于该消息是否包含任何未保存的更改。 如果未进行任何更改,则会关闭消息,而不会显示保存对话框。 另一方面,如果消息包含未保存的更改,将显示一个保存对话框,提示用户保存草稿、放弃更改或取消操作。

closeAsync(callback?: (asyncResult: Office.AsyncResult<void>) => void): void;

参数

callback

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

可选。 方法完成后,使用单个参数 asyncResult(即 Office.AsyncResult 对象)调用在回调参数中传递的函数。

返回

void

注解

[ API 集:邮箱预览 ]

最低权限级别读/写项

适用的 Outlook 模式:邮件撰写

重要提示:该方法 closeAsync 处于预览阶段。 目前仅在 Outlook on Windows 中受支持。

错误

  • The operation was cancelled by the user:用户从保存对话框中选择“ 取消 ”。

  • The operation is not supported:方法 closeAsync 尝试关闭阅读窗格或现有草稿中的回复。

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/99-preview-apis/close-async.yaml

// This snippet closes the current message being composed and discards any unsaved changes when the optional property, discardItem, is set to true.
// The API call works on a new message being composed, a reply, or an existing draft.
// When discardItem is set to false or isn't defined on a new message with unsaved changes, the user is prompted to save a draft, discard the changes, or cancel the close operation.
Office.context.mailbox.item.closeAsync(
  { discardItem: true },
  (asyncResult) => {
    if (asyncResult.status === Office.AsyncResultStatus.Failed) {
      console.log("Action failed with error: " + asyncResult.error.message);
      return;
    }
  });

disableClientSignatureAsync(options, callback)

禁用 Outlook 客户端签名。

此方法的行为取决于加载项运行的客户端。

  • 在 Windows 版和 Mac 版 Outlook 中,发送帐户的 “新建邮件 ”和 “答复/转发 ”部分下的签名设置为 (无)

  • 在 Outlook 网页版 中,将禁用新邮件、答复和转发的签名选项。 方法也会禁用所选的签名。

  • 在 Android 版和 iOS 版 Outlook 中,将清除移动设备上保存的签名。

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

参数

options
Office.AsyncContextOptions

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

callback

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

可选。 方法完成后,使用单个参数 asyncResult(即 Office.AsyncResult 对象)调用在回调参数中传递的函数。

返回

void

注解

[ API set: Mailbox 1.10 ]

最低权限级别读/写项

适用的 Outlook 模式:邮件撰写

重要提示:从版本 4.2352.0 开始,Android 版 Outlook 和 iOS 上的 Message Compose 支持此方法。 有关 Outlook mobile 中支持的 API 的详细信息,请参阅移动设备上的 Outlook 中支持的 Outlook JavaScript API

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/90-other-item-apis/work-with-client-signatures.yaml

// Disable the client signature.
Office.context.mailbox.item.disableClientSignatureAsync(function(asyncResult) {
  if (asyncResult.status === Office.AsyncResultStatus.Succeeded) {
    console.log("disableClientSignatureAsync succeeded");
  } else {
    console.error(asyncResult.error);
  }
});

disableClientSignatureAsync(callback)

禁用 Outlook 客户端签名。

此方法的行为取决于加载项运行的客户端。

  • 在 Windows 版和 Mac 版 Outlook 中,发送帐户的 “新建邮件 ”和 “答复/转发 ”部分下的签名设置为 (无)

  • 在 Outlook 网页版 中,将禁用新邮件、答复和转发的签名选项。 方法也会禁用所选的签名。

  • 在 Android 版和 iOS 版 Outlook 中,将清除移动设备上保存的签名。

disableClientSignatureAsync(callback?: (asyncResult: Office.AsyncResult<void>) => void): void;

参数

callback

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

可选。 方法完成后,使用单个参数 asyncResult(即 Office.AsyncResult 对象)调用在回调参数中传递的函数。

返回

void

注解

[ API set: Mailbox 1.10 ]

最低权限级别读/写项

适用的 Outlook 模式:邮件撰写

重要提示:从版本 4.2352.0 开始,Android 版 Outlook 和 iOS 上的 Message Compose 支持此方法。 有关 Outlook mobile 中支持的 API 的详细信息,请参阅移动设备上的 Outlook 中支持的 Outlook JavaScript API

getAttachmentContentAsync(attachmentId, options, callback)

从邮件或约会中获取附件,并将其作为 AttachmentContent 对象返回。

方法 getAttachmentContentAsync 从项中获取具有指定标识符的附件。 最佳做法是,应从通话中获取附件的标识符,然后在同一 getAttachmentsAsync 会话中使用该标识符检索附件。 在 Outlook 网页版和移动设备上,附件标识符只在同一个会话中才有效。 当用户关闭应用时,会话结束,或者如果用户开始撰写内联窗体,然后弹出窗体以在单独的窗口中继续。

getAttachmentContentAsync(attachmentId: string, options: Office.AsyncContextOptions, callback?: (asyncResult: Office.AsyncResult<AttachmentContent>) => void): void;

参数

attachmentId

string

要获取的附件的标识符。

options
Office.AsyncContextOptions

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

callback

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

可选。 方法完成后,使用单个参数 asyncResult(即 Office.AsyncResult 对象)调用在 参数中callback传递的函数。 如果调用失败,属性 asyncResult.error 将包含错误代码,其中包含失败的原因。

返回

void

注解

[ API set: Mailbox 1.8 ]

最低权限级别读取项

适用的 Outlook 模式:邮件撰写

错误

  • AttachmentTypeNotSupported:不支持附件类型。 不支持的类型包括 RTF 格式的嵌入图像,或者电子邮件或日历项目以外的项目附件类型 (,例如联系人或任务项) 。

  • InvalidAttachmentId:附件标识符不存在。

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/40-attachments/get-attachment-content.yaml

// Gets the attachments of the current message or appointment in compose mode.
const options = { asyncContext: { currentItem: item } };
// The getAttachmentsAsync call can only be used in compose mode.
item.getAttachmentsAsync(options, callback);

function callback(result) {
  if (result.status === Office.AsyncResultStatus.Failed) {
    console.log(result.error.message);
    return;
  }

  if (result.value.length <= 0) {
    console.log("Mail item has no attachments.");
    return;
  }

  for (let i = 0; i < result.value.length; i++) {
    // Log the attachment type and its contents to the console.
    result.asyncContext.currentItem.getAttachmentContentAsync(result.value[i].id, handleAttachmentsCallback);
  }
}

getAttachmentContentAsync(attachmentId, callback)

从邮件或约会中获取附件,并将其作为 AttachmentContent 对象返回。

方法 getAttachmentContentAsync 从项中获取具有指定标识符的附件。 最佳做法是,应从通话中获取附件的标识符,然后在同一 getAttachmentsAsync 会话中使用该标识符检索附件。 在 Outlook 网页版和移动设备上,附件标识符只在同一个会话中才有效。 当用户关闭应用时,会话结束,或者如果用户开始撰写内联窗体,然后弹出窗体以在单独的窗口中继续。

getAttachmentContentAsync(attachmentId: string, callback?: (asyncResult: Office.AsyncResult<AttachmentContent>) => void): void;

参数

attachmentId

string

要获取的附件的标识符。

callback

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

可选。 方法完成后,使用单个参数 asyncResult(即 Office.AsyncResult 对象)调用在 参数中callback传递的函数。 如果调用失败,属性 asyncResult.error 将包含错误代码,其中包含失败的原因。

返回

void

注解

[ API set: Mailbox 1.8 ]

最低权限级别读取项

适用的 Outlook 模式:邮件撰写

错误

  • AttachmentTypeNotSupported:不支持附件类型。 不支持的类型包括 RTF 格式的嵌入图像,或者电子邮件或日历项目以外的项目附件类型 (,例如联系人或任务项) 。

  • InvalidAttachmentId:附件标识符不存在。

getAttachmentsAsync(options, callback)

获取项的附件作为数组。

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

参数

options
Office.AsyncContextOptions

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

callback

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

可选。 方法完成后,使用类型的Office.AsyncResult单个参数调用在 参数中callback传递的函数。 如果调用失败,属性 asyncResult.error 将包含错误代码,其中包含失败的原因。

返回

void

注解

[ API set: Mailbox 1.8 ]

最低权限级别读取项

适用的 Outlook 模式:邮件撰写

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/40-attachments/attachments-compose.yaml

Office.context.mailbox.item.getAttachmentsAsync(function (result) {
    if (result.status !== Office.AsyncResultStatus.Succeeded) {
        console.error(result.error.message);
    } else {
        if (result.value.length > 0) {
            for (let i = 0; i < result.value.length; i++) {
                const attachment = result.value[i];
                console.log("ID: " + attachment.id + "\n" +
                    "Name: " + attachment.name + "\n" +
                    "Size: " + attachment.size + "\n" +
                    "isInline: " + attachment.isInline);
                switch (attachment.attachmentType) {
                    case Office.MailboxEnums.AttachmentType.Cloud:
                        console.log("Attachment type: Attachment is stored in a cloud location.");
                        break;
                    case Office.MailboxEnums.AttachmentType.File:
                        console.log("Attachment type: Attachment is a file.");
                        break;
                    case Office.MailboxEnums.AttachmentType.Item:
                        console.log("Attachment type: Attachment is an Exchange item.");
                        break;
                }
            }
        }
        else {
            console.log("No attachments on this message.");
        }
    }
});

getAttachmentsAsync(callback)

获取项的附件作为数组。

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

参数

callback

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

可选。 方法完成后,使用类型的Office.AsyncResult单个参数调用在 参数中callback传递的函数。 如果调用失败,属性 asyncResult.error 将包含错误代码,其中包含失败的原因。

返回

void

注解

[ API set: Mailbox 1.8 ]

最低权限级别读取项

适用的 Outlook 模式:邮件撰写

getComposeTypeAsync(options, callback)

指定邮件撰写的类型及其强制类型。 邮件可以是新邮件,也可以是答复或转发。 强制类型可以是 HTML 或纯文本。

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

参数

options
Office.AsyncContextOptions

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

callback

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

方法完成后,使用类型的Office.AsyncResult单个参数调用在 参数中callback传递的函数。 成功时, asyncResult.value 属性包含具有项的撰写类型和强制类型的对象。

返回

void

具有 ComposeType 消息项的 和 CoercionType 枚举值的对象。

注解

[ API set: Mailbox 1.10 ]

最低权限级别读取项

适用的 Outlook 模式:邮件撰写

重要提示:从版本 4.2352.0 开始,Android 版 Outlook 和 iOS 支持此方法。 有关 Outlook mobile 中支持的 API 的详细信息,请参阅移动设备上的 Outlook 中支持的 Outlook JavaScript API

getComposeTypeAsync(callback)

指定邮件撰写的类型及其强制类型。 邮件可以是新邮件,也可以是答复或转发。 强制类型可以是 HTML 或纯文本。

getComposeTypeAsync(callback: (asyncResult: Office.AsyncResult<any>) => void): void;

参数

callback

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

方法完成后,使用类型的Office.AsyncResult单个参数调用在 参数中callback传递的函数。 成功时, asyncResult.value 属性包含具有项的撰写类型和强制类型的对象。

返回

void

具有 ComposeType 消息项的 和 CoercionType 枚举值的对象。

注解

[ API set: Mailbox 1.10 ]

最低权限级别读取项

适用的 Outlook 模式:邮件撰写

重要提示:从版本 4.2352.0 开始,Android 版 Outlook 和 iOS 支持此方法。 有关 Outlook mobile 中支持的 API 的详细信息,请参阅移动设备上的 Outlook 中支持的 Outlook JavaScript API

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/90-other-item-apis/work-with-client-signatures.yaml

// Get the compose type of the current message.
Office.context.mailbox.item.getComposeTypeAsync(function(asyncResult) {
  if (asyncResult.status === Office.AsyncResultStatus.Succeeded) {
    console.log(
      "getComposeTypeAsync succeeded with composeType: " +
        asyncResult.value.composeType +
        " and coercionType: " +
        asyncResult.value.coercionType
    );
  } else {
    console.error(asyncResult.error);
  }
});

getConversationIndexAsync(options, callback)

注意

此 API 以预览状态提供给开发者,可能根据我们收到的反馈更改。 请勿在生产环境中使用此 API。

获取会话线程中当前消息的 Base64 编码位置。

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

参数

options
Office.AsyncContextOptions

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

callback

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

方法完成后,使用单个参数 asyncResult(即 Office.AsyncResult 对象)调用在 参数中callback传递的函数。 在 属性中返回 asyncResult.value 会话中当前消息的 Base64 编码位置。

返回

void

注解

[ API 集:邮箱预览 ]

最低权限级别读取项

适用的 Outlook 模式:邮件撰写

重要提示:若要预览 getConversationIndexAsync 方法,必须安装 Outlook on Windows 版本 2402 (内部版本 17317.20000) 或更高版本。 然后,加入 Microsoft 365 预览体验计划 ,并选择 “Beta 频道” 选项以访问 Office beta 版本。

提示:可以使用会话索引在会话线程中查找消息。 然后,使用其内容为正在撰写的当前消息提供上下文。

getConversationIndexAsync(callback)

注意

此 API 以预览状态提供给开发者,可能根据我们收到的反馈更改。 请勿在生产环境中使用此 API。

获取会话线程中当前消息的 Base64 编码位置。

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

参数

callback

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

方法完成后,使用单个参数 asyncResult(即 Office.AsyncResult 对象)调用在 参数中callback传递的函数。 在 属性中返回 asyncResult.value 会话中当前消息的 Base64 编码位置。

返回

void

注解

[ API 集:邮箱预览 ]

最低权限级别读取项

适用的 Outlook 模式:邮件撰写

重要提示:若要预览 getConversationIndexAsync 方法,必须安装 Outlook on Windows 版本 2402 (内部版本 17317.20000) 或更高版本。 然后,加入 Microsoft 365 预览体验计划 ,并选择 “Beta 频道” 选项以访问 Office beta 版本。

提示:可以使用会话索引在会话线程中查找消息。 然后,使用其内容为正在撰写的当前消息提供上下文。

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/99-preview-apis/get-conversation-index.yaml

// This snippet returns the Base64-encoded position of the current message in a conversation thread (PR_CONVERSATION_INDEX).
// The API call is supported on a message being composed and isn't supported on read items or appointments.
Office.context.mailbox.item.getConversationIndexAsync((result) => {
   if (result.status === Office.AsyncResultStatus.Failed) {
      console.log(result.error.message);
      return;
   }
   
   const conversationIndex = result.value;
   if (conversationIndex) {
      console.log("Position in the conversation thread: " + conversationIndex);
   } else {
      console.log("The current message doesn't belong to a conversation thread.");
   }
});

getInitializationContextAsync(options, callback)

获取当 加载项被可操作消息激活时传递的初始化数据。

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

参数

options
Office.AsyncContextOptions

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

callback

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

方法完成后,使用类型的Office.AsyncResult单个参数调用在 参数中callback传递的函数。 成功时,初始化上下文数据以字符串 (或空字符串的形式提供(如果 属性中 asyncResult.value 没有初始化上下文) )。

返回

void

注解

[ API set: Mailbox 1.8 ]

最低权限级别读取项

适用的 Outlook 模式:邮件撰写

示例

// Get the initialization context (if present).
Office.context.mailbox.item.getInitializationContextAsync((asyncResult) => {
    if (asyncResult.status === Office.AsyncResultStatus.Succeeded) {
        if (asyncResult.value.length > 0) {
            // The value is a string, parse to an object.
            const context = JSON.parse(asyncResult.value);
            // Do something with context.
        } else {
            // Empty context, treat as no context.
        }
    } else {
        // Handle the error.
    }
});

getInitializationContextAsync(callback)

获取当 加载项被可操作消息激活时传递的初始化数据。

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

参数

callback

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

方法完成后,使用类型的Office.AsyncResult单个参数调用在 参数中callback传递的函数。 成功时,初始化上下文数据以字符串 (或空字符串的形式提供(如果 属性中 asyncResult.value 没有初始化上下文) )。

返回

void

注解

[ API set: Mailbox 1.8 ]

最低权限级别读取项

适用的 Outlook 模式:邮件撰写

getItemClassAsync(options, callback)

注意

此 API 以预览状态提供给开发者,可能根据我们收到的反馈更改。 请勿在生产环境中使用此 API。

获取所选邮件的 Exchange Web Services 项类。

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

参数

options
Office.AsyncContextOptions

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

callback

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

方法完成后,使用单个参数 asyncResult(即 Office.AsyncResult 对象)调用在 参数中callback传递的函数。 消息类在 属性中 asyncResult.value 返回。

返回

void

注解

[ API 集:邮箱预览 ]

最低权限级别读取项

适用的 Outlook 模式:邮件撰写

重要说明

若要预览 getItemClassAsync 此方法,必须安装 Outlook on Windows 版本 2402 (内部版本 17317.20000) 或更高版本。 然后,加入 Microsoft 365 预览体验计划 ,并选择 “Beta 频道” 选项以访问 Office beta 版本。

下表列出了默认消息类。

Item 类 说明
Ipm。注意 新邮件和邮件答复
IPM.Schedule.Meeting.Request 会议请求
IPM.Schedule.Meeting.Canceled 会议取消
Ipm。Schedule.Meeting.Resp.Neg 响应以拒绝会议要求
Ipm。Schedule.Meeting.Resp.Pos 接受会议请求的响应
Ipm。Schedule.Meeting.Resp.Tent 响应以暂时接受会议要求

getItemClassAsync(callback)

注意

此 API 以预览状态提供给开发者,可能根据我们收到的反馈更改。 请勿在生产环境中使用此 API。

获取所选邮件的 Exchange Web Services 项类。

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

参数

callback

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

方法完成后,使用单个参数 asyncResult(即 Office.AsyncResult 对象)调用在 参数中callback传递的函数。 消息类在 属性中 asyncResult.value 返回。

返回

void

注解

[ API 集:邮箱预览 ]

最低权限级别读取项

适用的 Outlook 模式:邮件撰写

重要说明

若要预览 getItemClassAsync 此方法,必须安装 Outlook on Windows 版本 2402 (内部版本 17317.20000) 或更高版本。 然后,加入 Microsoft 365 预览体验计划 ,并选择 “Beta 频道” 选项以访问 Office beta 版本。

下表列出了默认消息类。

Item 类 说明
Ipm。注意 新邮件和邮件答复
IPM.Schedule.Meeting.Request 会议请求
IPM.Schedule.Meeting.Canceled 会议取消
Ipm。Schedule.Meeting.Resp.Neg 响应以拒绝会议要求
Ipm。Schedule.Meeting.Resp.Pos 接受会议请求的响应
Ipm。Schedule.Meeting.Resp.Tent 响应以暂时接受会议要求

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/99-preview-apis/get-item-class-async.yaml

// This snippet returns the Exchange Web Services item class property (PR_MESSAGE_CLASS) of the current mail item.
// The API call is only supported on a message being composed.
Office.context.mailbox.item.getItemClassAsync((asyncResult) => {
  if (asyncResult.status === Office.AsyncResultStatus.Failed) {
    console.log("Action failed with error: " + asyncResult.error.message);
    return;
  }

  console.log("Item class of the current mail item: " + asyncResult.value);
});

getItemIdAsync(options, callback)

异步获取已保存项的 ID。

调用时,此方法通过回调函数返回项 ID。

注意:如果你的外接程序在撰写模式下调用 getItemIdAsync 项目 (例如,若要获取 itemId 与 EWS 或 REST API) 一起使用,请注意,当 Outlook 处于缓存模式时,可能需要一段时间才能将项目同步到服务器。 在项目同步之前, itemId 无法识别,并且使用它将返回错误。

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

参数

options
Office.AsyncContextOptions

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

callback

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

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

返回

void

注解

[ API set: Mailbox 1.8 ]

最低权限级别读取项

适用的 Outlook 模式:邮件撰写

错误

  • ItemNotSaved:在保存项目之前,无法检索 ID。

getItemIdAsync(callback)

异步获取已保存项的 ID。

调用时,此方法通过回调函数返回项 ID。

注意:如果你的外接程序在撰写模式下调用 getItemIdAsync 项目 (例如,若要获取 itemId 与 EWS 或 REST API) 一起使用,请注意,当 Outlook 处于缓存模式时,可能需要一段时间才能将项目同步到服务器。 在项目同步之前, itemId 无法识别,并且使用它将返回错误。

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

参数

callback

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

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

返回

void

注解

[ API set: Mailbox 1.8 ]

最低权限级别读取项

适用的 Outlook 模式:邮件撰写

错误

  • ItemNotSaved:在保存项目之前,无法检索 ID。

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/85-tokens-and-service-calls/item-id-compose.yaml

Office.context.mailbox.item.getItemIdAsync(function (result) {
    if (result.status !== Office.AsyncResultStatus.Succeeded) {
        console.error(`getItemIdAsync failed with message: ${result.error.message}`);
    } else {
        console.log(result.value);
    }
});

getSelectedDataAsync(coercionType, options, callback)

以异步方式返回邮件的主题或正文中选定的数据。

如果没有选择,但光标位于正文或主题中,该方法将返回所选数据的空字符串。 如果选定的是字段,而不是正文或主题,则此方法返回 InvalidSelection 错误。

若要从回调函数访问所选数据,请调用 asyncResult.value.data。 若要访问所选内容来自的源属性,请调用 asyncResult.value.sourceProperty,它将为 bodysubject

getSelectedDataAsync(coercionType: Office.CoercionType | string, options: Office.AsyncContextOptions, callback: (asyncResult: Office.AsyncResult<any>) => void): void;

参数

coercionType

Office.CoercionType | string

请求数据的格式。 如果 Text为 ,则该方法返回字符串形式的纯文本,删除存在的任何 HTML 标记。 如果 Html为 ,则该方法返回所选文本,无论是纯文本还是 HTML。

options
Office.AsyncContextOptions

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

callback

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

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

返回

void

所选数据作为字符串,格式由 coercionType确定。

注解

[ API set: Mailbox 1.2 ]

最低权限级别读取项

适用的 Outlook 模式:邮件撰写

示例

// Get selected data.
Office.initialize = function () {
    Office.context.mailbox.item.getSelectedDataAsync(Office.CoercionType.Text, {}, getCallback);
};

function getCallback(asyncResult) {
    const text = asyncResult.value.data;
    const prop = asyncResult.value.sourceProperty;

    console.log("Selected text in " + prop + ": " + text);
}

getSelectedDataAsync(coercionType, callback)

以异步方式返回邮件的主题或正文中选定的数据。

如果没有选择,但光标位于正文或主题中,该方法将返回所选数据的空字符串。 如果选定的是字段,而不是正文或主题,则此方法返回 InvalidSelection 错误。

若要从回调函数访问所选数据,请调用 asyncResult.value.data。 若要访问所选内容来自的源属性,请调用 asyncResult.value.sourceProperty,它将为 bodysubject

getSelectedDataAsync(coercionType: Office.CoercionType | string, callback: (asyncResult: Office.AsyncResult<any>) => void): void;

参数

coercionType

Office.CoercionType | string

请求数据的格式。 如果 Text为 ,则该方法返回字符串形式的纯文本,删除存在的任何 HTML 标记。 如果 Html为 ,则该方法返回所选文本,无论是纯文本还是 HTML。

callback

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

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

返回

void

所选数据作为字符串,格式由 coercionType确定。

注解

[ API set: Mailbox 1.2 ]

最低权限级别读取项

适用的 Outlook 模式:邮件撰写

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/20-item-body/get-selected-data.yaml

Office.context.mailbox.item.getSelectedDataAsync(Office.CoercionType.Text, function(asyncResult) {
  if (asyncResult.status === Office.AsyncResultStatus.Succeeded) {
    const text = asyncResult.value.data;
    const prop = asyncResult.value.sourceProperty;
    console.log("Selected text in " + prop + ": " + text);
  } else {
    console.error(asyncResult.error);
  }
});

getSharedPropertiesAsync(options, callback)

获取共享文件夹或共享邮箱中约会或邮件的属性。

有关使用此 API 的详细信息,请参阅 在 Outlook 外接程序中启用共享文件夹和共享邮箱方案。

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

参数

options
Office.AsyncContextOptions

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

callback

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

方法完成后,使用单个参数 asyncResult(即 Office.AsyncResult 对象)调用在 参数中callback传递的函数。 属性 asyncResult.value 提供共享项的属性。

返回

void

注解

[ API set: Mailbox 1.8 for shared folder support, Mailbox 1.13 for shared mailbox support ]

最低权限级别读取项

适用的 Outlook 模式:邮件撰写

注意:iOS 或 Android 版 Outlook 不支持此方法。

重要提示:在消息撰写模式下,除非满足以下条件,否则Outlook 网页版或 Windows 不支持此 API。

a. 委托访问权限/共享文件夹

  1. 邮箱所有者启动邮件。 这可以是新邮件、答复或转发。

  2. 他们保存邮件,然后将其从自己的 Drafts 文件夹移动到与委托共享的文件夹。

  3. 委托从共享文件夹中打开草稿,然后继续撰写。

b. 共享邮箱 (仅适用于 Windows 版 Outlook)

  1. 共享邮箱用户启动邮件。 这可以是新邮件、答复或转发。

  2. 他们保存邮件,然后将其从自己的 Drafts 文件夹移动到共享邮箱中的文件夹。

  3. 另一个共享邮箱用户打开共享邮箱中的草稿,然后继续撰写。

消息现在位于共享上下文中,支持这些共享方案的加载项可以获取项的共享属性。 邮件发送后,通常位于发件人的 “已发送邮件” 文件夹中。

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/65-delegates-and-shared-folders/get-shared-properties.yaml

if (!Office.context.mailbox.item.getSharedPropertiesAsync) {
  console.error("Try this sample on a message from a shared folder.");
  return;
}

Office.context.mailbox.getCallbackTokenAsync({ isRest: true }, function(result) {
  if (result.status === Office.AsyncResultStatus.Succeeded && result.value !== "") {
    Office.context.mailbox.item.getSharedPropertiesAsync(
      {
        // Pass auth token along.
        asyncContext: result.value
      },
      function(result2) {
        let sharedProperties = result2.value;
        let delegatePermissions = sharedProperties.delegatePermissions;

        // Determine if user has the appropriate permission to do the operation.
        if ((delegatePermissions & Office.MailboxEnums.DelegatePermissions.Read) != 0) {
          const ewsId = Office.context.mailbox.item.itemId;
          const restId = Office.context.mailbox.convertToRestId(ewsId, Office.MailboxEnums.RestVersion.v2_0);
          let rest_url =
            sharedProperties.targetRestUrl + "/v2.0/users/" + sharedProperties.targetMailbox + "/messages/" + restId;

          $.ajax({
            url: rest_url,
            dataType: "json",
            headers: { Authorization: "Bearer " + result2.asyncContext }
          })
            .done(function(response) {
              console.log(response);
            })
            .fail(function(error) {
              console.error(error);
            });
        }
      }
    );
  }
});

getSharedPropertiesAsync(callback)

获取共享文件夹或共享邮箱中约会或邮件的属性。

有关使用此 API 的详细信息,请参阅 在 Outlook 外接程序中启用共享文件夹和共享邮箱方案。

getSharedPropertiesAsync(callback: (asyncResult: Office.AsyncResult<SharedProperties>) => void): void;

参数

callback

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

方法完成后,使用单个参数 asyncResult(即 Office.AsyncResult 对象)调用在 参数中callback传递的函数。 属性 asyncResult.value 提供共享项的属性。

返回

void

注解

[ API set: Mailbox 1.8 for shared folder support, Mailbox 1.13 for shared mailbox support ]

最低权限级别读取项

适用的 Outlook 模式:邮件撰写

注意:iOS 或 Android 版 Outlook 不支持此方法。

重要提示:在消息撰写模式下,除非满足以下条件,否则Outlook 网页版或 Windows 不支持此 API。

a. 委托访问权限/共享文件夹

  1. 邮箱所有者启动邮件。 这可以是新邮件、答复或转发。

  2. 他们保存邮件,然后将其从自己的 Drafts 文件夹移动到与委托共享的文件夹。

  3. 委托从共享文件夹中打开草稿,然后继续撰写。

b. 共享邮箱 (仅适用于 Windows 版 Outlook)

  1. 共享邮箱用户启动邮件。 这可以是新邮件、答复或转发。

  2. 他们保存邮件,然后将其从自己的 Drafts 文件夹移动到共享邮箱中的文件夹。

  3. 另一个共享邮箱用户打开共享邮箱中的草稿,然后继续撰写。

消息现在位于共享上下文中,支持这些共享方案的加载项可以获取项的共享属性。 邮件发送后,通常位于发件人的 “已发送邮件” 文件夹中。

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/65-delegates-and-shared-folders/get-shared-properties.yaml

if (!Office.context.mailbox.item.getSharedPropertiesAsync) {
  console.error("Try this sample on an item from a shared folder.");
  return;
}

Office.context.mailbox.item.getSharedPropertiesAsync(function(result) {
  console.log(result.value);
});

isClientSignatureEnabledAsync(options, callback)

获取是否启用了客户端签名。

对于 Windows 和 Mac 富客户端,如果新邮件、答复或转发的默认签名设置为发送 Outlook 帐户的模板,则 API 调用应返回 true 。 对于Outlook 网页版,如果为撰写类型 newMail、 或 forward启用了签名,reply则 API 调用应返回 true 。 如果在 Mac 或 Windows 富客户端中将设置设置为“ (无) ”,或者在 Outlook 网页版中禁用,则 API 调用应返回 false

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

参数

options
Office.AsyncContextOptions

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

callback

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

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

返回

void

注解

[ API set: Mailbox 1.10 ]

最低权限级别读取项

适用的 Outlook 模式:邮件撰写

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/90-other-item-apis/work-with-client-signatures.yaml

// Check if the client signature is currently enabled.
Office.context.mailbox.item.isClientSignatureEnabledAsync(function(asyncResult) {
  if (asyncResult.status === Office.AsyncResultStatus.Succeeded) {
    console.log("isClientSignatureEnabledAsync succeeded with result: " + asyncResult.value);
  } else {
    console.error(asyncResult.error);
  }
});

isClientSignatureEnabledAsync(callback)

获取是否启用了客户端签名。

对于 Windows 和 Mac 富客户端,如果新邮件、答复或转发的默认签名设置为发送 Outlook 帐户的模板,则 API 调用应返回 true 。 对于Outlook 网页版,如果为撰写类型 newMail、 或 forward启用了签名,reply则 API 调用应返回 true 。 如果在 Mac 或 Windows 富客户端中将设置设置为“ (无) ”,或者在 Outlook 网页版中禁用,则 API 调用应返回 false

isClientSignatureEnabledAsync(callback: (asyncResult: Office.AsyncResult<boolean>) => void): void;

参数

callback

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

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

返回

void

注解

[ API set: Mailbox 1.10 ]

最低权限级别读取项

适用的 Outlook 模式:邮件撰写

loadCustomPropertiesAsync(callback, userContext)

异步加载所选项目上此外接程序的自定义属性。

自定义属性以键值对的形式存储在每个应用、每个项目的基础上。 此方法在回调中返回 CustomProperties 对象,该对象提供访问特定于当前项和当前加载项的自定义属性的方法。 自定义属性不会对项进行加密,因此不应将其用作安全存储。

自定义属性作为 asyncResult.value 属性中的 CustomProperties 对象提供。 此对象可用于从邮件项获取、设置、保存和删除自定义属性。

loadCustomPropertiesAsync(callback: (asyncResult: Office.AsyncResult<CustomProperties>) => void, userContext?: any): void;

参数

callback

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

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

userContext

any

可选。 开发人员可以提供他们想要在回调函数中访问的任何对象。 此对象可以通过回调函数中的 asyncResult.asyncContext 属性进行访问。

返回

void

注解

[ API set: Mailbox 1.1 ]

若要了解有关自定义属性的详细信息,请参阅 获取和设置 Outlook 外接程序的外接程序元数据。

最低权限级别读取项

适用的 Outlook 模式:邮件撰写

示例

// The following example shows how to use the loadCustomPropertiesAsync method
// to asynchronously load custom properties that are specific to the current item.
// The example also shows how to use the saveAsync method to save these properties
// back to the server. After loading the custom properties, the example uses the
// get method to read the custom property myProp, the set method to write the
// custom property otherProp, and then finally calls the saveAsync method to save
// the custom properties.
Office.initialize = function () {
    // Checks for the DOM to load using the jQuery ready method.
    $(document).ready(function () {
        // After the DOM is loaded, add-in-specific code can run.
        const mailbox = Office.context.mailbox;
        mailbox.item.loadCustomPropertiesAsync(customPropsCallback);
    });
};

function customPropsCallback(asyncResult) {
    const customProps = asyncResult.value;
    const myProp = customProps.get("myProp");

    customProps.set("otherProp", "value");
    customProps.saveAsync(saveCallback);
}

function saveCallback(asyncResult) {
}
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/15-item-custom-properties/load-set-get-save.yaml

Office.context.mailbox.item.loadCustomPropertiesAsync(function (result) {
  if (result.status === Office.AsyncResultStatus.Succeeded) {
    console.log("Loaded following custom properties:");
    customProps = result.value;
    const dataKey = Object.keys(customProps)[0];
    const data = customProps[dataKey];
    for (let propertyName in data)
    {
      let propertyValue = data[propertyName];
      console.log(`${propertyName}: ${propertyValue}`);
    }              
  }
  else {
    console.error(`loadCustomPropertiesAsync failed with message ${result.error.message}`);
  }
});

removeAttachmentAsync(attachmentId, options, callback)

将附件从邮件或约会中删除。

removeAttachmentAsync 方法删除项目中带指定标识符的附件。 最佳做法是,仅当同一个邮件应用程序在同一会话中添加了一个附件时,你才应使用该附件标识符来删除该附件。 在 Outlook 网页版和移动设备上,附件标识符只在同一个会话中才有效。 当用户关闭应用时,会话结束,或者如果用户开始撰写内联窗体,然后弹出窗体以在单独的窗口中继续。

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

参数

attachmentId

string

要删除的附件的标识符。 在 Outlook 网页版 和 Windows 中,attachmentId的最大字符串长度为 200 个字符。

options
Office.AsyncContextOptions

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

callback

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

可选。 方法完成后,使用类型的Office.AsyncResult单个参数调用在 参数中callback传递的函数。 如果删除附件失败,asyncResult.error 属性将包含一个说明失败原因的错误代码。

返回

void

注解

[ API set: Mailbox 1.1 ]

最低权限级别读/写项

适用的 Outlook 模式:邮件撰写

错误

  • InvalidAttachmentId:附件标识符不存在。

示例

// The following code removes an attachment with an identifier of '0'.
Office.context.mailbox.item.removeAttachmentAsync(
    '0',
    { asyncContext : null },
    function (asyncResult)
    {
        console.log(asyncResult.status);
    }
);
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/40-attachments/attachments-compose.yaml

Office.context.mailbox.item.removeAttachmentAsync(
    $("#attachmentId").val(),
    { asyncContext : null },
    function(result)
    {
        if (result.status !== Office.AsyncResultStatus.Succeeded) {
            console.error(`${result.error.message}`);
        } else {
            console.log(`Attachment removed successfully.`);
        }
    }
);

removeAttachmentAsync(attachmentId, callback)

将附件从邮件或约会中删除。

removeAttachmentAsync 方法删除项目中带指定标识符的附件。 最佳做法是,仅当同一个邮件应用程序在同一会话中添加了一个附件时,你才应使用该附件标识符来删除该附件。 在 Outlook 网页版和移动设备上,附件标识符只在同一个会话中才有效。 当用户关闭应用时,会话结束,或者如果用户开始撰写内联窗体,然后弹出窗体以在单独的窗口中继续。

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

参数

attachmentId

string

要删除的附件的标识符。 在 Outlook 网页版 和 Windows 中,attachmentId的最大字符串长度为 200 个字符。

callback

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

可选。 方法完成后,使用类型的Office.AsyncResult单个参数调用在 参数中callback传递的函数。 如果删除附件失败,asyncResult.error 属性将包含一个说明失败原因的错误代码。

返回

void

注解

[ API set: Mailbox 1.1 ]

最低权限级别读/写项

适用的 Outlook 模式:邮件撰写

错误

  • InvalidAttachmentId:附件标识符不存在。

removeHandlerAsync(eventType, options, callback)

删除受支持事件类型的事件处理程序。 注意:事件仅适用于任务窗格实现。

有关支持的事件,请参阅 Item 对象模型 事件部分

removeHandlerAsync(eventType: Office.EventType | string, options: Office.AsyncContextOptions, callback?: (asyncResult: Office.AsyncResult<void>) => void): void;

参数

eventType

Office.EventType | string

应撤销处理程序的事件。

options
Office.AsyncContextOptions

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

callback

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

可选。 方法完成后,使用单个参数 asyncResult(即 Office.AsyncResult 对象)调用在 参数中callback传递的函数。

返回

void

注解

[ API set: Mailbox 1.7 ]

最低权限级别读取项

适用的 Outlook 模式:邮件撰写

removeHandlerAsync(eventType, callback)

删除受支持事件类型的事件处理程序。 注意:事件仅适用于任务窗格实现。

有关支持的事件,请参阅 Item 对象模型 事件部分

removeHandlerAsync(eventType: Office.EventType | string, callback?: (asyncResult: Office.AsyncResult<void>) => void): void;

参数

eventType

Office.EventType | string

应撤销处理程序的事件。

callback

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

可选。 方法完成后,使用单个参数 asyncResult(即 Office.AsyncResult 对象)调用在 参数中callback传递的函数。

返回

void

注解

[ API set: Mailbox 1.7 ]

最低权限级别读取项

适用的 Outlook 模式:邮件撰写

saveAsync(options, callback)

异步将当前消息保存为草稿。

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

参数

options
Office.AsyncContextOptions

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

callback

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

方法完成后,使用单个参数 asyncResult(即 Office.AsyncResult 对象)调用在 参数中callback传递的函数。 消息 ID 在 属性中 asyncResult.value 返回。

返回

void

注解

[ API 集:邮箱 1.3 ]

最低权限级别读/写项

适用的 Outlook 模式:邮件撰写

重要说明

  • 在 Outlook 网页版或 Outlook 联机模式下,该项目被保存到服务器中。 在 Outlook 缓存模式下,该项目被保存到本地缓存中。

  • 使用 HTML 格式的内容时,请务必注意 Outlook 客户端可能会修改内容。 这意味着对 、 Body.setAsync甚至 saveAsyncBody.getAsync方法的后续调用可能不会产生相同的内容。

  • 如果你的外接程序在撰写模式下调用 saveAsync 某个项目,以便获取用于 EWS 或 REST API 的项目 ID,请注意,当 Outlook 处于缓存模式时,可能需要一段时间才能将项目实际同步到服务器。 在项目同步之前,使用项 ID 将返回错误。

  • 在 Outlook 网页版中,在将从共享邮箱帐户发送的邮件上调用 时saveAsync,保存草稿的邮箱帐户会有所不同。 如果发件人从其个人邮箱创建新邮件并在“ 发件人 ”字段中选择共享邮箱帐户, saveAsync 请将草稿保存到用户个人邮箱的 “草稿 ”文件夹中。 如果发件人在单独的浏览器选项卡中打开共享邮箱帐户, (通过 “打开另一个邮箱 ”选项(例如,) 并在那里创建新邮件), saveAsync 则会将草稿保存到共享邮箱的 “草稿 ”文件夹中。

错误

  • InvalidAttachmentId:附件标识符不存在。

saveAsync(callback)

异步将当前消息保存为草稿。

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

参数

callback

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

方法完成后,使用单个参数 asyncResult(即 Office.AsyncResult 对象)调用在 参数中callback传递的函数。 消息 ID 在 属性中 asyncResult.value 返回。

返回

void

注解

[ API 集:邮箱 1.3 ]

最低权限级别读/写项

适用的 Outlook 模式:邮件撰写

重要说明

  • 在 Outlook 网页版或 Outlook 联机模式下,该项目被保存到服务器中。 在 Outlook 缓存模式下,该项目被保存到本地缓存中。

  • 使用 HTML 格式的内容时,请务必注意 Outlook 客户端可能会修改内容。 这意味着对 、 Body.setAsync甚至 saveAsyncBody.getAsync方法的后续调用可能不会产生相同的内容。

  • 如果你的外接程序在撰写模式下调用 saveAsync 某个项目,以便获取用于 EWS 或 REST API 的项目 ID,请注意,当 Outlook 处于缓存模式时,可能需要一段时间才能将项目实际同步到服务器。 在项目同步之前,使用项 ID 将返回错误。

  • 在 Outlook 网页版中,在将从共享邮箱帐户发送的邮件上调用 时saveAsync,保存草稿的邮箱帐户会有所不同。 如果发件人从其个人邮箱创建新邮件并在“ 发件人 ”字段中选择共享邮箱帐户, saveAsync 请将草稿保存到用户个人邮箱的 “草稿 ”文件夹中。 如果发件人在单独的浏览器选项卡中打开共享邮箱帐户, (通过 “打开另一个邮箱 ”选项(例如,) 并在那里创建新邮件), saveAsync 则会将草稿保存到共享邮箱的 “草稿 ”文件夹中。

错误

  • InvalidAttachmentId:附件标识符不存在。

示例

Office.context.mailbox.item.saveAsync(
    function callback(result) {
        // Process the result.
    });

// The following is an example of the
// `result` parameter passed to the
// callback function. The `value`
// property contains the item ID of
// the item.
{
    "value": "AAMkADI5...AAA=",
    "status": "succeeded"
}

setSelectedDataAsync(data, options, callback)

以异步方式将数据插入到邮件的正文或主题中。

方法 setSelectedDataAsync 在项目的主题或正文的光标位置插入指定的字符串,或者,如果在编辑器中选择了文本,则替换所选文本。 如果光标不在正文或主题字段中,则返回错误。 插入后,光标将置于插入内容的末尾。

setSelectedDataAsync(data: string, options: Office.AsyncContextOptions & CoercionTypeOptions, callback?: (asyncResult: Office.AsyncResult<void>) => void): void;

参数

data

string

要插入的数据。 数据不得超过 1,000,000 个字符。 如果传入的数据超过 1,000,000 个字符,则会引发 ArgumentOutOfRange 异常。

options

Office.AsyncContextOptions & Office.CoercionTypeOptions

包含以下一个或多个属性的对象文本:- asyncContext:开发人员可以在回调函数中提供他们想要访问的任何对象。 coercionType:如果为文本,则当前样式在 Outlook 网页版 和桌面客户端中应用。 如果字段是 HTML 编辑器,只会插入文本数据,即使数据为 HTML,也不例外。 如果 html 和 字段支持 HTML (主题不) ,则会在 Outlook 网页版 中应用当前样式,并在桌面客户端上的 Outlook 中应用默认样式。 如果该字段是文本字段,则返回 InvalidDataFormat 错误。 如果未设置 coercionType,则结果取决于该字段:如果该字段是 HTML,则使用 HTML;如果该字段是文本,则使用纯文本。

callback

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

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

返回

void

注解

[ API set: Mailbox 1.2 ]

最低权限级别读/写项

适用的 Outlook 模式:邮件撰写

错误

  • InvalidAttachmentId:附件标识符不存在。

示例

Office.context.mailbox.item.setSelectedDataAsync("<b>Hello World!</b>", { coercionType : "html" });
Office.context.mailbox.item.setSelectedDataAsync("Hello World!");
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/90-other-item-apis/set-selected-data.yaml

Office.context.mailbox.item.setSelectedDataAsync("Replaced", function(asyncResult) {
  if (asyncResult.status === Office.AsyncResultStatus.Succeeded) {
    console.log("Selected text has been updated successfully.");
  } else {
    console.error(asyncResult.error);
  }
});

setSelectedDataAsync(data, callback)

以异步方式将数据插入到邮件的正文或主题中。

方法 setSelectedDataAsync 在项目的主题或正文的光标位置插入指定的字符串,或者,如果在编辑器中选择了文本,则替换所选文本。 如果光标不在正文或主题字段中,则返回错误。 插入后,光标将置于插入内容的末尾。

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

参数

data

string

要插入的数据。 数据不得超过 1,000,000 个字符。 如果传入的数据超过 1,000,000 个字符,则会引发 ArgumentOutOfRange 异常。

callback

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

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

返回

void

注解

[ API set: Mailbox 1.2 ]

最低权限级别读/写项

适用的 Outlook 模式:邮件撰写

错误

  • InvalidAttachmentId:附件标识符不存在。