Office.AttachmentDetails interface
表示服务器中一个项目上的附件。 仅限阅读模式。
对象数 AttachmentDetails 组作为约会或消息项的属性返回 attachments 。
注解
最低权限级别: 读取项目
使用方
- Office.AppointmentRead: attachments
- Office.LoadedMessageRead: attachments
- Office.MessageRead: attachments
示例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/40-attachments/get-attachments-read.yaml
const item = Office.context.mailbox.item;
if (item.attachments.length > 0) {
for (let i = 0; i < item.attachments.length; i++) {
const attachment = item.attachments[i];
console.log(`${i+1}. Name: ${attachment.name}`);
console.log(`ID: ${attachment.id}`);
console.log(`Type: ${attachment.attachmentType}`);
console.log(`Inline content: ${attachment.isInline}`);
console.log(`Size: ${attachment.size}`);
}
} else {
console.log("This mail item doesn't contain any attachments.");
}
属性
| attachment |
获取指示附件类型的值。 |
| content |
获取内联附件的内容标识符。 |
| content |
获取附件的 MIME 内容类型。
警告: 虽然该 |
| id | 获取附件的 Exchange 附件 ID。 但是,如果附件类型为 |
| is |
获取一个值,该值指示附件是以图像形式显示在项目正文中,而不是在附件列表中。 |
| name | 获取附件的名称。 |
| size | 获取以字节为单位的附件大小。 |
属性详细信息
attachmentType
获取指示附件类型的值。
attachmentType: MailboxEnums.AttachmentType | string;
属性值
Office.MailboxEnums.AttachmentType | string
contentId
获取内联附件的内容标识符。
contentId: string;
属性值
string
注解
重要提示:2025 年 11 月 15 日发布的 Outlook 网页版和新版 Outlook on Windows 中 Outlook 电子邮件 HTML 正文中内联图像的表示方式的更改。 以前,图像的附件 ID 显示在适用<img>元素的属性中src。 现在,图像由属性中 src) 的内容 ID (cid 表示。 如果从 HTML 编辑器分析附件 ID 或从属性中的 src URL 获取图像的 Base64 编码值,则必须更新加载项的分析逻辑。 有关详细信息,请参阅 Outlook 网页版和新版 Outlook for Windows 中对内联图像表示形式的更改。
contentType
警告
现已弃用此 API。
If you require specific content types, grab the attachment's extension and process accordingly.
获取附件的 MIME 内容类型。
警告: 虽然该 contentType 值是附件扩展名的直接查找,但不会主动维护内部映射,因此此属性已弃用。 如果您需要特定类型,请获取附件的扩展名并相应地处理。 有关详细信息,请参阅 相关博客文章。
contentType: string;
属性值
string
id
获取附件的 Exchange 附件 ID。 但是,如果附件类型为 MailboxEnums.AttachmentType.Cloud,则返回文件的 URL。
id: string;
属性值
string
isInline
获取一个值,该值指示附件是以图像形式显示在项目正文中,而不是在附件列表中。
isInline: boolean;
属性值
boolean
name
获取附件的名称。
name: string;
属性值
string
注解
重要提示:附件类型 Office.MailboxEnums.AttachmentType.Item 不会返回属性中的 name 文件扩展名。
size
获取以字节为单位的附件大小。
size: number;
属性值
number