Office.AttachmentDetailsCompose interface

表示项目上的附件。 仅限撰写模式。

对象数组 AttachmentDetailsComposegetAttachmentsAsync 方法返回。

注解

[ API set: Mailbox 1.8 ]

最低权限级别读取项

适用的 Outlook 模式:Compose

示例

// 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((result) => {
  if (result.status === Office.AsyncResultStatus.Failed) {
    console.error(result.error.message);
    return;
  }

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

属性

attachmentType

获取一个值,该值指示附件的类型。

contentId

获取内联附件的内容标识符。

重要说明

  • 属性contentId仅在 Outlook 网页版 和 Windows 上的 Outlook 中受支持, (新的和经典 (预览版) ) 。 若要在经典 Outlook on Windows 中预览 contentId 属性,Outlook 客户端必须运行版本 2510 (内部版本 19312.20000) 或更高版本,并且必须在 Beta 频道上。 有关详细信息,请参阅 Microsoft 365 预览体验计划

  • 从 2025 年 11 月 15 日开始,更改内联图像在 Outlook 网页版 中 Outlook 电子邮件的 HTML 正文中的表示方式,新的 Windows 版 Outlook 将开始向生产用户推出。 以前,图像的附件 ID 显示在适用<img>元素的 属性中src。 更改后,图像将由属性中src的内容 ID (cid) 来表示。 因此,如果从 HTML 编辑器分析附件 ID,或者从 属性中的 URL src 获取图像的 Base64 值,则需要更新加载项分析逻辑。 有关详细信息,请参阅更改Outlook 网页版中的内联图像表示形式和新的 Outlook for Windows

id

获取附件的索引。

isInline

获取一个值,该值指示附件在项目正文中而不是附件列表中是否显示为图像。

name

获取附件的名称。

size

获取以字节为单位的附件大小。

url

如果附件的类型为 MailboxEnums.AttachmentType.Cloud,则获取其 URL。

属性详细信息

attachmentType

获取一个值,该值指示附件的类型。

attachmentType: MailboxEnums.AttachmentType | string;

属性值

注解

重要说明

  • 在Outlook 网页版和新的 Outlook on Windows 中,本地保存的邮件或约会,然后使用拖放或“附加项目”选项进行附加, 类型Office.MailboxEnums.AttachmentType.File为 。 文件扩展名在 属性中 name 返回。 但是,使用 “转发为附件 ”选项附加的邮件或约会的类型 Office.MailboxEnums.AttachmentType.Item为 。 在这种情况下,不会在 属性中 name 返回扩展。

  • 在经典 Outlook on Windows 中,使用拖放、 附加文件作为附件转发 附加的邮件或约会的类型 Office.MailboxEnums.AttachmentType.Item为 。 属性中 name 不返回文件扩展名。

  • 在 Outlook on Mac 中,使用拖放、 附加项目转发作为附件附加 的邮件或约会的类型 Office.MailboxEnums.AttachmentType.File为 。 文件扩展名在 属性中 name 返回。

contentId

获取内联附件的内容标识符。

重要说明

  • 属性contentId仅在 Outlook 网页版 和 Windows 上的 Outlook 中受支持, (新的和经典 (预览版) ) 。 若要在经典 Outlook on Windows 中预览 contentId 属性,Outlook 客户端必须运行版本 2510 (内部版本 19312.20000) 或更高版本,并且必须在 Beta 频道上。 有关详细信息,请参阅 Microsoft 365 预览体验计划

  • 从 2025 年 11 月 15 日开始,更改内联图像在 Outlook 网页版 中 Outlook 电子邮件的 HTML 正文中的表示方式,新的 Windows 版 Outlook 将开始向生产用户推出。 以前,图像的附件 ID 显示在适用<img>元素的 属性中src。 更改后,图像将由属性中src的内容 ID (cid) 来表示。 因此,如果从 HTML 编辑器分析附件 ID,或者从 属性中的 URL src 获取图像的 Base64 值,则需要更新加载项分析逻辑。 有关详细信息,请参阅更改Outlook 网页版中的内联图像表示形式和新的 Outlook for Windows

contentId: string;

属性值

string

id

获取附件的索引。

id: string;

属性值

string

isInline

获取一个值,该值指示附件在项目正文中而不是附件列表中是否显示为图像。

isInline: boolean;

属性值

boolean

name

获取附件的名称。

name: string;

属性值

string

注解

重要说明

  • 类型的 Office.MailboxEnums.AttachmentType.Item 附件不会在 属性中 name 返回文件扩展名。

  • 在Outlook 网页版和新的 Outlook on Windows 中,本地保存的邮件或约会,然后使用拖放或“附加项目”选项进行附加, 类型Office.MailboxEnums.AttachmentType.File为 。 文件扩展名在 属性中 name 返回。 但是,使用 “转发为附件 ”选项附加的邮件或约会的类型 Office.MailboxEnums.AttachmentType.Item为 。 在这种情况下,不会在 属性中 name 返回扩展。

  • 在经典 Outlook on Windows 中,使用拖放、 附加项目转发作为附件附加 的邮件或约会的类型 Office.MailboxEnums.AttachmentType.Item为 。 属性中 name 不返回文件扩展名。 附加的日历项

  • 在 Outlook on Mac 中,使用拖放、 附加项目转发作为附件附加 的邮件或约会的类型 Office.MailboxEnums.AttachmentType.File为 。 文件扩展名在 属性中 name 返回。

size

获取以字节为单位的附件大小。

size: number;

属性值

number

url

如果附件的类型为 MailboxEnums.AttachmentType.Cloud,则获取其 URL。

url?: string;

属性值

string