Office.AppointmentCompose interface

Office.context.mailbox.item 的约会组织者模式。

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

父接口:

扩展

注解

使用方

属性

body

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

categories

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

end

获取或设置约会结束的日期和时间。

end 属性是一个 “时间” 对象,表示为协调世界时 (UTC) 日期和时间值。 可以使用该 convertToLocalClientTime 方法将属性值转换为 end 客户端的本地日期和时间。

使用 Time.setAsync 方法设置结束时间时,应使用 convertToUtcClientTime 方法将客户端的本地时间转换为服务器的 UTC。

重要提示: 在 Windows 客户端中,不能使用此属性更新定期结束。

enhancedLocation

获取或设置约会的位置。 该 enhancedLocation 属性返回一个 EnhancedLocation 对象,该对象提供用于获取、删除或添加项上的位置的方法。

isAllDayEvent

获取或设置约会的 Office.IsAllDayEvent 属性。

itemType

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

itemType 属性返回其中一个 ItemType 枚举值,指示 item 对象实例是邮件还是约会。

location

获取或设置约会的位置。 该 location 属性返回一个 Location 对象,该对象提供用于获取和设置约会位置的方法。

notificationMessages

获取项目的通知邮件。

optionalAttendees

提供对事件的可选与会者的访问权限。 对象的类型和访问级别取决于当前项目的模式。

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

organizer

获取指定会议的组织者。

organizer 属性返回一个 Organizer 对象,该对象提供获取 Organizer 值的方法。

recurrence

获取或设置约会的重复周期模式。

recurrence如果项目是系列或系列中的实例,则该属性将返回定期约会或会议请求的定期对象。 null 为单个约会和单个约会的会议请求返回。

注意: 会议请求的值IPM.Schedule.Meeting.RequestitemClass

注意:如果定期对象为 null,则指示对象是单个约会或单个约会的会议请求,而不是系列的一部分。

requiredAttendees

提供对事件的必需与会者的访问权限。 对象的类型和访问级别取决于当前项目的模式。

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

sensitivity

获取或设置约会的 敏感度级别 。 有关敏感度级别的信息,请参阅 将电子邮件标记为普通、个人、私人或机密

sensitivityLabel

获取对象以获取或设置约会的 敏感度标签

seriesId

获取实例所属系列的 ID。

在 Outlook 网页版 中,在 Windows (新的和经典的) 上,以及在 Mac 上,该seriesId属性返回此项目所属的父 (系列) 项的 Exchange Web 服务 (EWS) ID。 但是,在 Android 和 iOS 上的 Outlook 中, seriesId 返回父项的 REST ID。

注意:该属性返回的 seriesId 标识符与 Exchange Web 服务项标识符相同。 该 seriesId 属性与 Outlook REST API 使用的 Outlook ID 并不完全相同。 在使用此值进行 REST API 调用之前,应使用 Office.context.mailbox.convertToRestId. 有关更多详细信息,请参阅 通过 Outlook 加载项使用 Outlook REST API。

seriesId该属性null返回没有父项的项目(如单个约会、系列项目或会议请求),并返回undefined非会议请求的任何其他项目。

sessionData

在 Compose 模式下管理项的 SessionData

重要提示:在支持邮箱 1.15 或更早版本的 Outlook 客户端中,每个邮件项的整个 SessionData 对象限制为每个加载项 50,000 个字符。 在支持邮箱 1.16 或更高版本的客户端中,每个加载项的字符限制为 2,621,440 个字符。

start

获取或设置约会开始的日期和时间。

start 属性是一个 “时间” 对象,表示为协调世界时 (UTC) 日期和时间值。 可以使用该 convertToLocalClientTime 方法将值转换为客户端的本地日期和时间。

使用 Time.setAsync 方法设置开始时间时,应使用 convertToUtcClientTime 方法将客户端的本地时间转换为服务器的 UTC。

重要提示: 在 Windows 客户端中,不能使用此属性更新定期的开头。

subject

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

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

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

方法

addFileAttachmentAsync(uri, attachmentName, options, callback)

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

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

addFileAttachmentAsync(uri, attachmentName, callback)

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

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

addFileAttachmentFromBase64Async(base64File, attachmentName, options, callback)

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

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

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

addFileAttachmentFromBase64Async(base64File, attachmentName, callback)

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

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

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

addHandlerAsync(eventType, handler, options, callback)

添加支持事件的事件处理程序。 事件仅在任务窗格加载项中可用。

addHandlerAsync(eventType, handler, callback)

添加支持事件的事件处理程序。 事件仅在任务窗格加载项中可用。

addItemAttachmentAsync(itemId, attachmentName, options, callback)

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

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

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

如果 Office 加载项在 Outlook 网页版和 Windows 上的新 Outlook 中运行,则该addItemAttachmentAsync方法可将项目附加到你正在编辑的项目以外的项目。 但是,不支持并且不建议这样做。

addItemAttachmentAsync(itemId, attachmentName, callback)

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

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

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

如果 Office 加载项在 Outlook 网页版和 Windows 上的新 Outlook 中运行,则该addItemAttachmentAsync方法可将项目附加到你正在编辑的项目以外的项目。 但是,不支持并且不建议这样做。

close()

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

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

在 Windows (经典) 和 Mac 上的 Outlook 中,此 close 方法对“阅读窗格”中的回复没有影响。

disableClientSignatureAsync(options, callback)

禁用 Outlook 客户端签名。

在 Windows (经典) 和 Mac 上的 Outlook 中,此 API 将发送帐户的“新邮件”和“答复/转发”部分下的签名设置为“ (无) ”,从而有效地禁用签名。 在 Outlook 网页版和新的 Outlook on Windows 中,API 禁用新邮件、答复和转发的签名选项。 如果选择了签名,则此 API 调用将禁用它。

disableClientSignatureAsync(callback)

禁用 Outlook 客户端签名。

在 Windows (经典) 和 Mac 上的 Outlook 中,此 API 将发送帐户的“新邮件”和“答复/转发”部分下的签名设置为“ (无) ”,从而有效地禁用签名。 在 Outlook 网页版和新的 Outlook on Windows 中,API 禁用新邮件、答复和转发的签名选项。 如果选择了签名,则此 API 调用将禁用它。

getAttachmentContentAsync(attachmentId, options, callback)

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

getAttachmentContentAsync(attachmentId, callback)

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

getAttachmentsAsync(options, callback)

以数组形式获取项的附件。

getAttachmentsAsync(callback)

以数组形式获取项的附件。

getInitializationContextAsync(options, callback)

获取由 可操作邮件激活加载项时传递的初始化数据。

getInitializationContextAsync(callback)

获取由 可操作邮件激活加载项时传递的初始化数据。

getItemIdAsync(options, callback)

异步获取 Exchange Web 服务 (EWS) 已保存项目的项目标识符。

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

getItemIdAsync(callback)

异步获取 Exchange Web 服务 (EWS) 已保存项目的项目标识符。

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

getSelectedDataAsync(coercionType, options, callback)

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

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

要从回调函数访问所选数据,请调用 asyncResult.value.data。 要访问所选内容来自的source属性,请调用asyncResult.value.sourceProperty ,这将是 bodysubject或 。

getSelectedDataAsync(coercionType, callback)

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

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

要从回调函数访问所选数据,请调用 asyncResult.value.data。 要访问所选内容来自的source属性,请调用asyncResult.value.sourceProperty ,这将是 bodysubject或 。

getSharedPropertiesAsync(options, callback)

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

有关使用此 API 的详细信息,请参阅在 Outlook 加载项中启用共享文件夹和共享邮箱方案

getSharedPropertiesAsync(callback)

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

有关使用此 API 的详细信息,请参阅在 Outlook 加载项中启用共享文件夹和共享邮箱方案

isClientSignatureEnabledAsync(options, callback)

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

在 Outlook 网页版和新的 Outlook on Windows 中,如果为撰写类型newMail启用签名,则返回 truereplyforward或 。 如果在 Windows (经典) 或 Mac 上的 Outlook 中将设置设置为“无 () ”,或者在 Windows 上的 Outlook 网页版 或新版 Outlook 中禁用,则返回 false

isClientSignatureEnabledAsync(callback)

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

在 Outlook 网页版和新的 Outlook on Windows 中,如果为撰写类型newMail启用签名,则返回 truereplyforward或 。 如果在 Windows (经典) 或 Mac 上的 Outlook 中将设置设置为“无 () ”,或者在 Windows 上的 Outlook 网页版 或新版 Outlook 中禁用,则返回 false

loadCustomPropertiesAsync(callback, userContext)

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

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

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

removeAttachmentAsync(attachmentId, options, callback)

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

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

removeAttachmentAsync(attachmentId, callback)

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

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

removeHandlerAsync(eventType, options, callback)

删除受支持事件类型的事件处理程序。 事件仅在任务窗格加载项中可用。

removeHandlerAsync(eventType, callback)

删除受支持事件类型的事件处理程序。 事件仅在任务窗格加载项中可用。

saveAsync(options, callback)

异步保存项目。

由于约会没有草稿状态,因此,如果在撰写模式下对约会调用,则 saveAsync 项目将在用户日历上另存为普通约会。 对于之前尚未保存的新约会,不会发送邀请。 对于现有约会,将向已添加或已删除的与会者发送更新。

saveAsync(callback)

异步保存项目。

由于约会没有草稿状态,因此,如果在撰写模式下对约会调用,则 saveAsync 项目将在用户日历上另存为普通约会。 对于之前尚未保存的新约会,不会发送邀请。 对于现有约会,将向已添加或已删除的与会者发送更新。

sendAsync(options, callback)

发送正在撰写的约会。

sendAsync(callback)

发送正在撰写的约会。

setSelectedDataAsync(data, options, callback)

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

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

setSelectedDataAsync(data, callback)

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

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

属性详细信息

body

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

body: Body;

属性值

注解

API 集:邮箱 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 an object that is passed as the result parameter to the callback function.
{
    "value": "TEXT of whole body (including threads below)",
    "status": "succeeded",
    "asyncContext": "This is passed to the callback"
}

categories

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

categories: Categories;

属性值

注解

API 集:邮箱 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);
  }
});

end

获取或设置约会结束的日期和时间。

end 属性是一个 “时间” 对象,表示为协调世界时 (UTC) 日期和时间值。 可以使用该 convertToLocalClientTime 方法将属性值转换为 end 客户端的本地日期和时间。

使用 Time.setAsync 方法设置结束时间时,应使用 convertToUtcClientTime 方法将客户端的本地时间转换为服务器的 UTC。

重要提示: 在 Windows 客户端中,不能使用此属性更新定期结束。

end: Time;

属性值

注解

最低权限级别读取项目

适用的 Outlook 模式:约会组织者

示例

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

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

  const time = result.value;
  const localTime = Office.context.mailbox.convertToLocalClientTime(time);
  console.log(`Appointment ends (local): ${localTime.month + 1}/${localTime.date}/${localTime.year}, ${localTime.hours}:${localTime.minutes}:${localTime.seconds}`);
});

...

Office.context.mailbox.item.start.getAsync((result) => {
  if (result.status !== Office.AsyncResultStatus.Succeeded) {
    console.error(`Get start date failed with message ${result.error.message}`);
    return;
  }

  const end = result.value; // Set end to current start date and time.
  end.setDate(end.getDate() + 1); // Set end as 1 day later than start date.
  Office.context.mailbox.item.end.setAsync(end, (result) => {
    if (result.status !== Office.AsyncResultStatus.Succeeded) {
      console.error(`Set end date failed with message ${result.error.message}`);
      return;
    }
    console.log(`Successfully set end date and time to ${end}`);
  });
});

enhancedLocation

获取或设置约会的位置。 该 enhancedLocation 属性返回一个 EnhancedLocation 对象,该对象提供用于获取、删除或添加项上的位置的方法。

enhancedLocation: EnhancedLocation;

属性值

注解

API 集:邮箱 1.8

最低权限级别读取项目

适用的 Outlook 模式:约会组织者

重要提示:若要在不支持邮箱要求集 1.8 的 Outlook 客户端中管理约会位置,请改用 location 该属性。 有关为方案选择正确的位置 API 的指南,请参阅“在 Outlook 中撰写指定内容时获取或设置位置”。

示例

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

Office.context.mailbox.item.enhancedLocation.getAsync((result) => {
  if (result.status !== Office.AsyncResultStatus.Succeeded) {
    console.error(`Failed to get locations. Error message: ${result.error.message}`);
    return;
  }
  const places = result.value;
  if (places && places.length > 0) {
    result.value.forEach(function(place) {
      console.log(`Location: ${place.displayName} (type: ${place.locationIdentifier.type})`);
      if (place.locationIdentifier.type === Office.MailboxEnums.LocationType.Room) {
        console.log("Email address: " + place.emailAddress);
      }
    });
  } else {
    console.log("There are no locations.");
  }
});

...

const locations = [
  {
    id: "Contoso",
    type: Office.MailboxEnums.LocationType.Custom
  },
  {
    id: "room500@test.com",
    type: Office.MailboxEnums.LocationType.Room
  }
];
Office.context.mailbox.item.enhancedLocation.addAsync(locations, (result) => {
  if (result.status === Office.AsyncResultStatus.Succeeded) {
    console.log(`Successfully added locations ${JSON.stringify(locations)}`);
  } else {
    console.error(`Failed to add locations. Error message: ${result.error.message}`);
  }
});

...

const locations = [
  {
    id: "Contoso",
    type: Office.MailboxEnums.LocationType.Custom
  },
  {
    id: "room500@test.com",
    type: Office.MailboxEnums.LocationType.Room
  }
];
Office.context.mailbox.item.enhancedLocation.removeAsync(locations, (result) => {
  if (result.status === Office.AsyncResultStatus.Succeeded) {
    console.log(`Successfully removed locations ${JSON.stringify(locations)}`);
  } else {
    console.error(`Failed to remove locations. Error message: ${result.error.message}`);
  }
});

isAllDayEvent

注意

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

获取或设置约会的 Office.IsAllDayEvent 属性。

isAllDayEvent: IsAllDayEvent;

属性值

注解

API 集:邮箱预览

最低权限级别读取项目

适用的 Outlook 模式:约会组织者

示例

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

Office.context.mailbox.item.isAllDayEvent.getAsync(function(asyncResult) {
  if (asyncResult.status === Office.AsyncResultStatus.Succeeded) {
    console.log("Is this an all-day event? " + asyncResult.value);
  } else {
    console.log("Failed to get if this is an all-day event. Error: " + JSON.stringify(asyncResult.error));
  }
});

...

Office.context.mailbox.item.isAllDayEvent.setAsync(true, function(asyncResult) {
  if (asyncResult.status === Office.AsyncResultStatus.Failed) {
    console.log("Failed to set all-day event: " + JSON.stringify(asyncResult.error));
  } else {
    console.log("Appointment set to all-day event.");
  }
});

itemType

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

itemType 属性返回其中一个 ItemType 枚举值,指示 item 对象实例是邮件还是约会。

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

location

获取或设置约会的位置。 该 location 属性返回一个 Location 对象,该对象提供用于获取和设置约会位置的方法。

location: Location;

属性值

注解

API 集:邮箱 1.1

最低权限级别读取项目

适用的 Outlook 模式:约会组织者

重要提示:此 enhancedLocation 属性是在邮箱要求集 1.8 中引入的。 使用该属性更好地 enhancedLocation 识别和管理约会位置,尤其是在您需要确定位置类型的情况下。 有关为方案选择正确的位置 API 的指南,请参阅“在 Outlook 中撰写指定内容时获取或设置位置”。

示例

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

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

...

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

notificationMessages

获取项目的通知邮件。

notificationMessages: NotificationMessages;

属性值

注解

API 集:邮箱 1.3

最低权限级别读取项目

适用的 Outlook 模式:约会组织者

重要说明

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

  • Android 或 iOS 上的 Outlook 不支持此属性。 有关 Outlook 移动版中支持的 API 的详细信息,请参阅移动设备上的 Outlook 支持的 Outlook JavaScript API

示例

// 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, (result) => {
  if (result.status === Office.AsyncResultStatus.Failed) {
    console.log(`Failed to add progress notification with id = ${id}. Try using a different ID.`);
    return;
  }
  console.log(`Added progress notification with id = ${id}.`);
});

...

// 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, (result) => {
  if (result.status === Office.AsyncResultStatus.Failed) {
    console.log(`Failed to add informational notification with id = ${id}. Try using a different ID.`);
    return;
  }
  console.log(`Added informational notification with id = ${id}.`);
});

...

// 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, (result) => {
  if (result.status === Office.AsyncResultStatus.Failed) {
    console.log(`Failed to add persistent informational notification with id = ${id}. Try using a different ID.`);
    return;
  }
  console.log(`Added persistent informational notification with id = ${id}.`);
});

...

// 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(JSON.stringify(asyncResult.value));
});

...

// 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
  },
  (result) => {
    if (result.status === Office.AsyncResultStatus.Failed) {
      console.log(`Failed to replace notification with id = ${id}. ${result.error.message}.`);
      return;
    }
    console.log(`Replaced notification with id = ${id}.`);
  });

...

// Removes a notification message from the current mail item.
const id = (document.getElementById("notificationId") as HTMLInputElement).value;
Office.context.mailbox.item.notificationMessages.removeAsync(id, (result) => {
  if (result.status === Office.AsyncResultStatus.Failed) {
    console.log(`Failed to remove notification with id = ${id}. ${result.error.message}.`);
    return;
  }
  console.log(`Removed notification with id = ${id}.`);
});

optionalAttendees

提供对事件的可选与会者的访问权限。 对象的类型和访问级别取决于当前项目的模式。

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

optionalAttendees: Recipients;

属性值

注解

最低权限级别读取项目

适用的 Outlook 模式:约会组织者

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/30-recipients-and-attendees/get-set-optional-attendees-appointment-organizer.yaml

Office.context.mailbox.item.optionalAttendees.getAsync(function(asyncResult) {
  if (asyncResult.status === Office.AsyncResultStatus.Succeeded) {
    const apptOptionalAttendees = asyncResult.value;
    for (let i = 0; i < apptOptionalAttendees.length; i++) {
      console.log(
        "Optional attendees: " +
          apptOptionalAttendees[i].displayName +
          " (" +
          apptOptionalAttendees[i].emailAddress +
          ") - response: " +
          apptOptionalAttendees[i].appointmentResponse
      );
    }
  } else {
    console.error(asyncResult.error);
  }
});

...

const email = (document.getElementById("emailOptional") as HTMLInputElement).value;
const emailArray = [email];
Office.context.mailbox.item.optionalAttendees.setAsync(emailArray, function(asyncResult) {
  if (asyncResult.status === Office.AsyncResultStatus.Succeeded) {
    console.log("Succeeded in setting optional attendees field.");
  } else {
    console.error(asyncResult.error);
  }
});

organizer

获取指定会议的组织者。

organizer 属性返回一个 Organizer 对象,该对象提供获取 Organizer 值的方法。

organizer: Organizer;

属性值

注解

API 集:邮箱 1.7

最低权限级别读取/写入项目

适用的 Outlook 模式:约会组织者

示例

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

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

recurrence

获取或设置约会的重复周期模式。

recurrence如果项目是系列或系列中的实例,则该属性将返回定期约会或会议请求的定期对象。 null 为单个约会和单个约会的会议请求返回。

注意: 会议请求的值IPM.Schedule.Meeting.RequestitemClass

注意:如果定期对象为 null,则指示对象是单个约会或单个约会的会议请求,而不是系列的一部分。

recurrence: Recurrence;

属性值

注解

API 集:邮箱 1.7

最低权限级别读取项目

适用的 Outlook 模式:约会组织者

示例

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

Office.context.mailbox.item.recurrence.getAsync(function(asyncResult) {
  if (asyncResult.status === Office.AsyncResultStatus.Succeeded) {
    const recurrence = asyncResult.value;
    if (recurrence === null) {
      console.log("This is a single appointment.");
    } else {
      console.log(`Recurrence pattern: ${JSON.stringify(recurrence)}`);
    }
  } else {
    console.error(asyncResult.error);
  }
});

...

// Important: Can only set the recurrence pattern of an appointment series.

const currentDate = new Date();
let seriesTimeObject: Office.SeriesTime;
// Set series start date to tomorrow.
seriesTimeObject.setStartDate(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDay() + 1);
// Set series end date to one year from now.
seriesTimeObject.setEndDate(currentDate.getFullYear() + 1, currentDate.getMonth() + 1, currentDate.getDay());
// Set start time to 1:30 PM.
seriesTimeObject.setStartTime(13, 30);
// Set duration to 30 minutes.
seriesTimeObject.setDuration(30);

const pattern = {
  seriesTime: seriesTimeObject,
  recurrenceType: Office.MailboxEnums.RecurrenceType.Yearly,
  recurrenceProperties: {
    interval: 1,
    dayOfWeek: Office.MailboxEnums.Days.Tue,
    weekNumber: Office.MailboxEnums.WeekNumber.Second,
    month: Office.MailboxEnums.Month.Sep
  },
  recurrenceTimeZone: { name: Office.MailboxEnums.RecurrenceTimeZone.PacificStandardTime }
};

Office.context.mailbox.item.recurrence.setAsync(pattern as any, (asyncResult) => {
  if (asyncResult.status !== Office.AsyncResultStatus.Succeeded) {
    console.error(`Failed to set recurrence. Error: ${asyncResult.error.message}`);
    return;
  }
  console.log(`Succeeded in setting recurrence pattern ${JSON.stringify(pattern)}`);
});

requiredAttendees

提供对事件的必需与会者的访问权限。 对象的类型和访问级别取决于当前项目的模式。

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

requiredAttendees: Recipients;

属性值

注解

最低权限级别读取项目

适用的 Outlook 模式:约会组织者

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/30-recipients-and-attendees/get-set-required-attendees-appointment-organizer.yaml

Office.context.mailbox.item.requiredAttendees.getAsync(function(asyncResult) {
  if (asyncResult.status === Office.AsyncResultStatus.Succeeded) {
    const apptRequiredAttendees = asyncResult.value;
    for (let i = 0; i < apptRequiredAttendees.length; i++) {
      console.log(
        "Required attendees: " +
          apptRequiredAttendees[i].displayName +
          " (" +
          apptRequiredAttendees[i].emailAddress +
          ") - response: " +
          apptRequiredAttendees[i].appointmentResponse
      );
    }
  } else {
    console.error(asyncResult.error);
  }
});

...

const email = (document.getElementById("emailRequired") as HTMLInputElement).value;
const emailArray = [email];
Office.context.mailbox.item.requiredAttendees.setAsync(emailArray, function(asyncResult) {
  if (asyncResult.status === Office.AsyncResultStatus.Succeeded) {
    console.log("Succeeded in setting required attendees field.");
  } else {
    console.error(asyncResult.error);
  }
});

sensitivity

获取或设置约会的 敏感度级别 。 有关敏感度级别的信息,请参阅 将电子邮件标记为普通、个人、私人或机密

sensitivity: Sensitivity;

属性值

注解

API 集:邮箱 1.14

最低权限级别读取项目

适用的 Outlook 模式:约会组织者

重要提示: Outlook 网页版、Windows 上的新 Outlook 和 Mac 上的 Outlook 仅支持普通和专用敏感度级别。

示例

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

Office.context.mailbox.item.sensitivity.getAsync(function(asyncResult) {
  if (asyncResult.status === Office.AsyncResultStatus.Succeeded) {
    console.log("Sensitivity: " + asyncResult.value);
  } else {
    console.log("Failed to get sensitivity: " + JSON.stringify(asyncResult.error));
  }
});

...

Office.context.mailbox.item.sensitivity.setAsync(
  Office.MailboxEnums.AppointmentSensitivityType.Private,
  function callback(asyncResult) {
    if (asyncResult.status === Office.AsyncResultStatus.Failed) {
      console.log("Failed to set appointment sensitivity: " + JSON.stringify(asyncResult.error));
    } else {
      console.log("Successfully set appointment sensitivity.");
    }
  }
);

sensitivityLabel

获取对象以获取或设置约会的 敏感度标签

sensitivityLabel: SensitivityLabel;

属性值

注解

API 集:邮箱 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 网页版 中,在 Windows (新的和经典的) 上,以及在 Mac 上,该seriesId属性返回此项目所属的父 (系列) 项的 Exchange Web 服务 (EWS) ID。 但是,在 Android 和 iOS 上的 Outlook 中, seriesId 返回父项的 REST ID。

注意:该属性返回的 seriesId 标识符与 Exchange Web 服务项标识符相同。 该 seriesId 属性与 Outlook REST API 使用的 Outlook ID 并不完全相同。 在使用此值进行 REST API 调用之前,应使用 Office.context.mailbox.convertToRestId. 有关更多详细信息,请参阅 通过 Outlook 加载项使用 Outlook REST API。

seriesId该属性null返回没有父项的项目(如单个约会、系列项目或会议请求),并返回undefined非会议请求的任何其他项目。

seriesId: string;

属性值

string

注解

API 集:邮箱 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

在 Compose 模式下管理项的 SessionData

重要提示:在支持邮箱 1.15 或更早版本的 Outlook 客户端中,每个邮件项的整个 SessionData 对象限制为每个加载项 50,000 个字符。 在支持邮箱 1.16 或更高版本的客户端中,每个加载项的字符限制为 2,621,440 个字符。

sessionData: SessionData;

属性值

注解

API 集:邮箱 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));
  }
});

start

获取或设置约会开始的日期和时间。

start 属性是一个 “时间” 对象,表示为协调世界时 (UTC) 日期和时间值。 可以使用该 convertToLocalClientTime 方法将值转换为客户端的本地日期和时间。

使用 Time.setAsync 方法设置开始时间时,应使用 convertToUtcClientTime 方法将客户端的本地时间转换为服务器的 UTC。

重要提示: 在 Windows 客户端中,不能使用此属性更新定期的开头。

start: Time;

属性值

注解

最低权限级别读取项目

适用的 Outlook 模式:约会组织者

示例

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

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

  const time = result.value;
  const localTime = Office.context.mailbox.convertToLocalClientTime(time);
  console.log(`Appointment starts (local): ${localTime.month + 1}/${localTime.date}/${localTime.year}, ${localTime.hours}:${localTime.minutes}:${localTime.seconds}`);
});

...

const start = new Date(); // Represents current date and time.
start.setDate(start.getDate() + 2); // Add 2 days to current date.
Office.context.mailbox.item.start.setAsync(start, (result) => {
  if (result.status !== Office.AsyncResultStatus.Succeeded) {
    console.error(`Action failed with message ${result.error.message}`);
    return;
  }
  console.log(`Successfully set start date and time to ${start}`);
});

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

方法详细信息

addFileAttachmentAsync(uri, attachmentName, options, callback)

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

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

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

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

返回

void

注解

API 集:适用于 Windows (经典) 和 Mac 上的 Outlook 的邮箱 1.1、适用于 Windows 上的 Outlook 网页版 和新版 Outlook 的邮箱 1.8

最低权限级别读取/写入项目

适用的 Outlook 模式:约会组织者

重要说明

  • iOS 或 Android 上的 Outlook 不支持这种方法。 有关 Outlook 移动版中支持的 API 的详细信息,请参阅移动设备上的 Outlook 支持的 Outlook JavaScript API

  • 如果将位图 (BMP) 图像添加为内联附件,则不支持它们。

  • 在最新版本的经典 Outlook on Windows 中,引入了一个 bug, (使用此 API 还是使用 Outlook UI) ,都会错误地将标头附加 Authorization: Bearer 到此操作。 若要解决此问题,请使用随要求集 1.8 一起引入的 addFileAttachmentFromBase64 API。

  • 要附加的文件的 URI 必须支持生产中的缓存。 托管图像的服务器不应返回 Cache-Control 在 HTTP 响应中指定 no-cacheno-store或类似选项的标头。 但是,在开发加载项和更改文件时,缓存可能会阻止你查看更改。 我们建议在开发过程中使用 Cache-Control 标头。

  • 可以将相同的 URI 与删除同一会话中的附件的方法一起使用 removeAttachmentAsync

错误

  • AttachmentSizeExceeded :附件超出允许的大小。

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

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

示例

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

const attachmentUrl = (document.getElementById("attachmentUrl") as HTMLInputElement).value;
Office.context.mailbox.item.addFileAttachmentAsync(
  attachmentUrl,
  getFileName(attachmentUrl),
  { isInline: false },
  (result) => {
    if (result.status === Office.AsyncResultStatus.Failed) {
      console.log(`Failed to add attachment: ${result.error.message}.`);
      return;
    }
    console.log(`Added attachment with ID: ${result.value}`);
  }
);

addFileAttachmentAsync(uri, attachmentName, callback)

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

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

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

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

返回

void

注解

API 集:适用于 Windows (经典) 和 Mac 上的 Outlook 的邮箱 1.1、适用于 Windows 上的 Outlook 网页版 和新版 Outlook 的邮箱 1.8

最低权限级别读取/写入项目

适用的 Outlook 模式:约会组织者

重要说明

  • iOS 或 Android 上的 Outlook 不支持这种方法。 有关 Outlook 移动版中支持的 API 的详细信息,请参阅移动设备上的 Outlook 支持的 Outlook JavaScript API

  • 如果将位图 (BMP) 图像添加为内联附件,则不支持它们。

  • 在最新版本的经典 Outlook on Windows 中,引入了一个 bug, (使用此 API 还是使用 Outlook UI) ,都会错误地将标头附加 Authorization: Bearer 到此操作。 若要解决此问题,请使用随要求集 1.8 一起引入的 addFileAttachmentFromBase64 API。

  • 要附加的文件的 URI 必须支持生产中的缓存。 托管图像的服务器不应返回 Cache-Control 在 HTTP 响应中指定 no-cacheno-store或类似选项的标头。 但是,在开发加载项和更改文件时,缓存可能会阻止你查看更改。 我们建议在开发过程中使用 Cache-Control 标头。

  • 可以将相同的 URI 与删除同一会话中的附件的方法一起使用 removeAttachmentAsync

错误

  • 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 编码内容。 编码字符串的最大长度是 34,865,152 个字符。 这对应于采用 Base64 编码前的最大附件大小 25 MB。

attachmentName

string

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

options

Office.AsyncContextOptions & { isInline: boolean }

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

callback

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

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

返回

void

注解

API 集:邮箱 1.8

最低权限级别读取/写入项目

适用的 Outlook 模式:约会组织者

重要说明

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

  • 若要将内联 Base64 编码的图像添加到正在撰写的消息或约会的正文,请使用 Body API 方法,例如 prependAsyncsetSignatureAsyncsetAsync。 如果用于 Office.context.mailbox.item.body.setAsync 插入图像,请先调用 Office.context.mailbox.item.body.getAsync 以获取项目的当前正文。 否则,图像在插入后将不会呈现在正文中。 有关示例,请参阅 Script Lab 中的“将内联 Base64 编码的图像添加到邮件或约会正文 (Compose) 示例。

错误

  • AttachmentSizeExceeded :附件超出允许的大小。

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

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

示例

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

const 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 },
  (result) => {
    if (result.status === Office.AsyncResultStatus.Failed) {
      console.log(`Failed to add attachment from Base64-encoded string: ${result.error.message}.`);
      return;
    }
    console.log(`Added attachment from a Base64-encoded string with ID: ${result.value}`);
  }
);

...

// 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 = (document.getElementById("signature") as HTMLInputElement).value + "<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 编码内容。 编码字符串的最大长度是 34,865,152 个字符。 这对应于采用 Base64 编码前的最大附件大小 25 MB。

attachmentName

string

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

callback

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

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

返回

void

注解

API 集:邮箱 1.8

最低权限级别读取/写入项目

适用的 Outlook 模式:约会组织者

重要说明

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

  • 若要将内联 Base64 编码的图像添加到正在撰写的消息或约会的正文,请使用 Body API 方法,例如 prependAsyncsetSignatureAsyncsetAsync。 如果用于 Office.context.mailbox.item.body.setAsync 插入图像,请先调用 Office.context.mailbox.item.body.getAsync 以获取项目的当前正文。 否则,图像在插入后将不会呈现在正文中。 有关示例,请参阅 Script Lab 中的“将内联 Base64 编码的图像添加到邮件或约会正文 (Compose) 示例。

错误

  • AttachmentSizeExceeded :附件超出允许的大小。

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

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

addHandlerAsync(eventType, handler, options, callback)

添加支持事件的事件处理程序。 事件仅在任务窗格加载项中可用。

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

可选。 当该方法完成时,将使用单个参数(一个对象)asyncResultOffice.AsyncResult调用传入参数的callback函数。

返回

void

注解

API 集:邮箱 1.7

最低权限级别读取项目

适用的 Outlook 模式:约会组织者

重要提示: 有关邮件项上支持的事件的列表,请参阅 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)

添加支持事件的事件处理程序。 事件仅在任务窗格加载项中可用。

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

可选。 当该方法完成时,将使用单个参数(一个对象)asyncResultOffice.AsyncResult调用传入参数的callback函数。

返回

void

注解

API 集:邮箱 1.7

最低权限级别读取项目

适用的 Outlook 模式:约会组织者

重要提示: 有关邮件项上支持的事件的列表,请参阅 Outlook 项对象模型

addItemAttachmentAsync(itemId, attachmentName, options, callback)

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

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

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

如果 Office 加载项在 Outlook 网页版和 Windows 上的新 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为 . 如果成功,附件标识符将在 asyncResult.value 属性中提供。 如果添加附件失败,asyncResult 对象将包含一个提供错误说明的 Error 对象。

返回

void

注解

API 集:邮箱 1.1

最低权限级别读取/写入项目

适用的 Outlook 模式:约会组织者

错误

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

示例

// The following example adds an existing Outlook item as an attachment
// with the name "My Attachment".
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, (result) => {
        if (result.status === Office.AsyncResultStatus.Failed) {
            console.error("Failed to add attachment: " + result.error.message);
            return;
        }

        console.log("Attachment added successfully.");
        console.log("var1: " + result.asyncContext.var1);
        console.log("var2: " + result.asyncContext.var2);
    });
}

addItemAttachmentAsync(itemId, attachmentName, callback)

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

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

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

如果 Office 加载项在 Outlook 网页版和 Windows 上的新 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为 . 如果成功,附件标识符将在 asyncResult.value 属性中提供。 如果添加附件失败,asyncResult 对象将包含一个提供错误说明的 Error 对象。

返回

void

注解

API 集:邮箱 1.1

最低权限级别读取/写入项目

适用的 Outlook 模式:约会组织者

错误

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

close()

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

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

在 Windows (经典) 和 Mac 上的 Outlook 中,此 close 方法对“阅读窗格”中的回复没有影响。

close(): void;

返回

void

注解

API 集:邮箱 1.3

最低权限级别受限

适用的 Outlook 模式:约会组织者

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

示例

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

disableClientSignatureAsync(options, callback)

禁用 Outlook 客户端签名。

在 Windows (经典) 和 Mac 上的 Outlook 中,此 API 将发送帐户的“新邮件”和“答复/转发”部分下的签名设置为“ (无) ”,从而有效地禁用签名。 在 Outlook 网页版和新的 Outlook on Windows 中,API 禁用新邮件、答复和转发的签名选项。 如果选择了签名,则此 API 调用将禁用它。

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

参数

options
Office.AsyncContextOptions

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

callback

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

可选。 该方法完成后,将使用单个参数(一个对象)asyncResultOffice.AsyncResult调用传入回调参数的函数。

返回

void

注解

API 集:邮箱 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

// 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 中,此 API 将发送帐户的“新邮件”和“答复/转发”部分下的签名设置为“ (无) ”,从而有效地禁用签名。 在 Outlook 网页版和新的 Outlook on Windows 中,API 禁用新邮件、答复和转发的签名选项。 如果选择了签名,则此 API 调用将禁用它。

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

参数

callback

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

可选。 该方法完成后,将使用单个参数(一个对象)asyncResultOffice.AsyncResult调用传入回调参数的函数。

返回

void

注解

API 集:邮箱 1.10

最低权限级别读取/写入项目

适用的 Outlook 模式:约会组织者

getAttachmentContentAsync(attachmentId, options, callback)

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

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

可选。 当该方法完成时,将使用单个参数(一个对象)asyncResultOffice.AsyncResult调用传入参数的callback函数。 如果调用失败, asyncResult.error 属性将包含一个错误代码以及失败的原因。

返回

void

注解

API 集:邮箱 1.8

最低权限级别读取项目

适用的 Outlook 模式:约会组织者

重要说明

  • getAttachmentContentAsync 方法从项目中获取具有指定标识符的附件。 作为最佳做法,应从调用中 getAttachmentsAsync 获取附件的标识符,然后在同一会话中使用该标识符检索附件。

  • 在 Outlook 网页版和 Windows 上的新版 Outlook 中,getAttachmentContentAsync不支持使用“上传并共享”选项添加的附件。

  • 在 Outlook 网页版、移动设备和 Windows 上的新 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. The getAttachmentsAsync call can only be used in compose mode.
Office.context.mailbox.item.getAttachmentsAsync((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.
    Office.context.mailbox.item.getAttachmentContentAsync(result.value[i].id, handleAttachmentsCallback);
  }
});

getAttachmentContentAsync(attachmentId, callback)

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

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

参数

attachmentId

string

要获取的附件的标识符。

callback

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

可选。 当该方法完成时,将使用单个参数(一个对象)asyncResultOffice.AsyncResult调用传入参数的callback函数。 如果调用失败, asyncResult.error 属性将包含一个错误代码以及失败的原因。

返回

void

注解

API 集:邮箱 1.8

最低权限级别读取项目

适用的 Outlook 模式:约会组织者

重要说明

  • getAttachmentContentAsync 方法从项目中获取具有指定标识符的附件。 作为最佳做法,应从调用中 getAttachmentsAsync 获取附件的标识符,然后在同一会话中使用该标识符检索附件。

  • 在 Outlook 网页版和 Windows 上的新版 Outlook 中,getAttachmentContentAsync不支持使用“上传并共享”选项添加的附件。

  • 在 Outlook 网页版、移动设备和 Windows 上的新 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

可选。 当该方法完成时, callback 将使用类型 Office.AsyncResult为 . 如果调用失败, asyncResult.error 属性将包含一个错误代码以及失败的原因。 如果调用成功,则会在属性中asyncResult.value返回一个对象数AttachmentDetailsCompose组。

返回

void

注解

API 集:邮箱 1.8

最低权限级别读取项目

适用的 Outlook 模式:约会组织者

重要提示: 在 Outlook 网页版和新的 Windows 版 Outlook 中,用户可以选择“上传并共享”选项将附件上传到 OneDrive,并在邮件项目中包含指向该文件的链接。 但是,由于仅包含链接, getAttachmentsAsync 因此不会返回此附件。

示例

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

getAttachmentsAsync(callback)

以数组形式获取项的附件。

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

参数

callback

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

可选。 当该方法完成时, callback 将使用类型 Office.AsyncResult为 . 如果调用失败, asyncResult.error 属性将包含一个错误代码以及失败的原因。 如果调用成功,则会在属性中asyncResult.value返回一个对象数AttachmentDetailsCompose组。

返回

void

注解

API 集:邮箱 1.8

最低权限级别读取项目

适用的 Outlook 模式:约会组织者

重要提示: 在 Outlook 网页版和新的 Windows 版 Outlook 中,用户可以选择“上传并共享”选项将附件上传到 OneDrive,并在邮件项目中包含指向该文件的链接。 但是,由于仅包含链接, getAttachmentsAsync 因此不会返回此附件。

getInitializationContextAsync(options, callback)

获取由 可操作邮件激活加载项时传递的初始化数据。

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

参数

options
Office.AsyncContextOptions

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

callback

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

当该方法完成时, callback 将使用类型 Office.AsyncResult为 . 成功后,初始化上下文数据将以字符串 (的形式提供,如果属性中 asyncResult.value 没有初始化上下文) 则为空字符串提供。

返回

void

注解

API 集:邮箱 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

当该方法完成时, callback 将使用类型 Office.AsyncResult为 . 成功后,初始化上下文数据将以字符串 (的形式提供,如果属性中 asyncResult.value 没有初始化上下文) 则为空字符串提供。

返回

void

注解

API 集:邮箱 1.8

最低权限级别读取项目

适用的 Outlook 模式:约会组织者

getItemIdAsync(options, callback)

异步获取 Exchange Web 服务 (EWS) 已保存项目的项目标识符。

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

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

参数

options
Office.AsyncContextOptions

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

callback

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

当该方法完成时, callback 将使用类型 Office.AsyncResult为 . 在属性中 asyncResult.value 返回项目的 EWS 项 ID。

返回

void

注解

API 集:邮箱 1.8

最低权限级别读取项目

适用的 Outlook 模式:约会组织者

重要说明

  • 返回的项 ID 与 Outlook 条目 ID 或 Outlook REST API 使用的 ID 并不完全相同。 在使用此值进行 REST API 调用之前,应使用 Office.context.mailbox.convertToRestId.

  • 例如,如果加载项调用 getItemIdAsync (,若要获取要用于 EWS 或 REST API) 的项 ID,请注意,当 Outlook 处于缓存模式时,可能需要一段时间才能将项目同步到服务器。 在同步项目之前,无法识别项目 ID,使用它将返回错误。

错误

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

getItemIdAsync(callback)

异步获取 Exchange Web 服务 (EWS) 已保存项目的项目标识符。

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

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

参数

callback

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

当该方法完成时, callback 将使用类型 Office.AsyncResult为 . 在属性中 asyncResult.value 返回项目的 EWS 项 ID。

返回

void

注解

API 集:邮箱 1.8

最低权限级别读取项目

适用的 Outlook 模式:约会组织者

重要说明

  • 返回的项 ID 与 Outlook 条目 ID 或 Outlook REST API 使用的 ID 并不完全相同。 在使用此值进行 REST API 调用之前,应使用 Office.context.mailbox.convertToRestId.

  • 例如,如果加载项调用 getItemIdAsync (,若要获取要用于 EWS 或 REST API) 的项 ID,请注意,当 Outlook 处于缓存模式时,可能需要一段时间才能将项目同步到服务器。 在同步项目之前,无法识别项目 ID,使用它将返回错误。

错误

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

示例

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

Office.context.mailbox.item.getItemIdAsync((result) => {
    if (result.status === Office.AsyncResultStatus.Failed) {
        console.error(`getItemIdAsync failed with message: ${result.error.message}`);
        return;
    }

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

getSelectedDataAsync(coercionType, options, callback)

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

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

要从回调函数访问所选数据,请调用 asyncResult.value.data。 要访问所选内容来自的source属性,请调用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

当该方法完成时, callback 将使用类型 Office.AsyncResult为 .

返回

void

所选数据为字符串,格式由 coercionType.

注解

API 集:邮箱 1.2

最低权限级别读取项目

适用的 Outlook 模式:约会组织者

示例

// Get selected data.
Office.context.mailbox.item.getSelectedDataAsync(Office.CoercionType.Text, { option1: "option1"}, 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。 要访问所选内容来自的source属性,请调用asyncResult.value.sourceProperty ,这将是 bodysubject或 。

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

参数

coercionType

Office.CoercionType | string

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

callback

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

当该方法完成时, callback 将使用类型 Office.AsyncResult为 .

返回

void

所选数据为字符串,格式由 coercionType.

注解

API 集:邮箱 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

当该方法完成时,将使用单个参数(一个对象)asyncResultOffice.AsyncResult调用传入参数的callback函数。 该 asyncResult.value 属性提供共享项的属性。

返回

void

注解

API 集:邮箱 1.8(用于支持共享文件夹),邮箱 1.13(用于支持共享邮箱)

最低权限级别读取项目

适用的 Outlook 模式:约会组织者

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

getSharedPropertiesAsync(callback)

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

有关使用此 API 的详细信息,请参阅在 Outlook 加载项中启用共享文件夹和共享邮箱方案

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

参数

callback

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

当该方法完成时,将使用单个参数(一个对象)asyncResultOffice.AsyncResult调用传入参数的callback函数。 该 asyncResult.value 属性提供共享项的属性。

返回

void

注解

API 集:邮箱 1.8(用于支持共享文件夹),邮箱 1.13(用于支持共享邮箱)

最低权限级别读取项目

适用的 Outlook 模式:约会组织者

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

示例

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

Office.context.mailbox.item.getSharedPropertiesAsync((result) => {
  if (result.status === Office.AsyncResultStatus.Failed) {
    console.error("The current folder or mailbox isn't shared.");
    return;
  }
  const sharedProperties = result.value;
  console.log(`Owner: ${sharedProperties.owner}`);
  console.log(`Permissions: ${sharedProperties.delegatePermissions}`);
  console.log(`Target mailbox: ${sharedProperties.targetMailbox}`);
});

isClientSignatureEnabledAsync(options, callback)

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

在 Outlook 网页版和新的 Outlook on Windows 中,如果为撰写类型newMail启用签名,则返回 truereplyforward或 。 如果在 Windows (经典) 或 Mac 上的 Outlook 中将设置设置为“无 () ”,或者在 Windows 上的 Outlook 网页版 或新版 Outlook 中禁用,则返回 false

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

参数

options
Office.AsyncContextOptions

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

callback

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

当该方法完成时, callback 将使用类型 Office.AsyncResult为 .

返回

void

注解

API 集:邮箱 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)

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

在 Outlook 网页版和新的 Outlook on Windows 中,如果为撰写类型newMail启用签名,则返回 truereplyforward或 。 如果在 Windows (经典) 或 Mac 上的 Outlook 中将设置设置为“无 () ”,或者在 Windows 上的 Outlook 网页版 或新版 Outlook 中禁用,则返回 false

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

参数

callback

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

当该方法完成时, callback 将使用类型 Office.AsyncResult为 .

返回

void

注解

API 集:邮箱 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

当该方法完成时, callback 将使用类型 Office.AsyncResult为 .

userContext

any

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

返回

void

注解

API 集:邮箱 1.1

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

最低权限级别读取项目

适用的 Outlook 模式:约会组织者

示例

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

  customProps = result.value;
  console.log("Loaded the CustomProperties object.");
});

removeAttachmentAsync(attachmentId, options, callback)

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

removeAttachmentAsync 方法删除项目中带指定标识符的附件。 最佳做法是,仅当同一个邮件应用程序在同一会话中添加了一个附件时,你才应使用该附件标识符来删除该附件。 在 Outlook 网页版、移动设备和 Windows 上的新 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

可选。 当该方法完成时, callback 将使用类型 Office.AsyncResult为 . 如果删除附件失败,asyncResult.error 属性将包含一个说明失败原因的错误代码。

返回

void

注解

API 集:邮箱 1.1

最低权限级别读取/写入项目

适用的 Outlook 模式:约会组织者

重要提示: 此 removeAttachmentAsync 方法不会从邮件项中删除内联附件。 要删除内联附件,请首先获取项目的正文,然后从其内容中删除附件的任何引用。 使用 Office.Body API 获取并设置项目的正文。

错误

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

示例

// 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(
  (document.getElementById("attachmentId") as HTMLInputElement).value,
  (result) => {
    if (result.status === Office.AsyncResultStatus.Failed) {
      console.error(result.error.message);
      return;
    }
    console.log(`Attachment removed successfully.`);
  }
);

removeAttachmentAsync(attachmentId, callback)

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

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

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

参数

attachmentId

string

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

callback

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

可选。 当该方法完成时, callback 将使用类型 Office.AsyncResult为 . 如果删除附件失败,asyncResult.error 属性将包含一个说明失败原因的错误代码。

返回

void

注解

API 集:邮箱 1.1

最低权限级别读取/写入项目

适用的 Outlook 模式:约会组织者

重要提示: 此 removeAttachmentAsync 方法不会从邮件项中删除内联附件。 要删除内联附件,请首先获取项目的正文,然后从其内容中删除附件的任何引用。 使用 Office.Body API 获取并设置项目的正文。

错误

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

removeHandlerAsync(eventType, options, callback)

删除受支持事件类型的事件处理程序。 事件仅在任务窗格加载项中可用。

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

可选。 当该方法完成时,将使用单个参数(一个对象)asyncResultOffice.AsyncResult调用传入参数的callback函数。

返回

void

注解

API 集:邮箱 1.7

最低权限级别读取项目

适用的 Outlook 模式:约会组织者

重要提示: 有关邮件项上支持的事件的列表,请参阅 Outlook 项对象模型

removeHandlerAsync(eventType, callback)

删除受支持事件类型的事件处理程序。 事件仅在任务窗格加载项中可用。

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

参数

eventType

Office.EventType | string

应撤销处理程序的事件。

callback

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

可选。 当该方法完成时,将使用单个参数(一个对象)asyncResultOffice.AsyncResult调用传入参数的callback函数。

返回

void

注解

API 集:邮箱 1.7

最低权限级别读取项目

适用的 Outlook 模式:约会组织者

重要提示: 有关邮件项上支持的事件的列表,请参阅 Outlook 项对象模型

示例

Office.context.mailbox.item.removeHandlerAsync(Office.EventType.InfobarClicked, (asyncResult) => {
    if (asyncResult.status === Office.AsyncResultStatus.Failed) {
        console.error("Failed to remove event handler: " + asyncResult.error.message);
        return;
    }

    console.log("Event handler removed successfully.");
});

saveAsync(options, callback)

异步保存项目。

由于约会没有草稿状态,因此,如果在撰写模式下对约会调用,则 saveAsync 项目将在用户日历上另存为普通约会。 对于之前尚未保存的新约会,不会发送邀请。 对于现有约会,将向已添加或已删除的与会者发送更新。

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

参数

options
Office.AsyncContextOptions

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

callback

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

当该方法完成时,将使用单个参数(一个对象)asyncResultOffice.AsyncResult调用传入参数的callback函数。 在属性中 asyncResult.value 返回 EWS 约会 ID。

返回

void

注解

API 集:邮箱 1.3

最低权限级别读取/写入项目

适用的 Outlook 模式:约会组织者

重要说明

  • 在 Outlook 网页版、新的 Windows 版 Outlook 或处于联机模式 (非缓存模式) 的经典 Windows 版 Outlook 中,项目将保存到服务器。 在 Outlook 缓存模式下,该项目被保存到本地缓存中。

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

  • 返回的标识符与 Exchange Web 服务 (EWS) 项标识符相同。 返回的项 ID 与 Outlook 条目 ID 或 Outlook REST API 使用的 ID 并不完全相同。 在使用此值进行 REST API 调用之前,应使用 Office.context.mailbox.convertToRestId.

  • 如果加载项调用 saveAsync 获取要用于 EWS 或 REST API 的项 ID,请注意,当 Outlook 处于缓存模式时,可能需要一段时间才能将项目实际同步到服务器。 在项同步之前,使用项 ID 将返回错误。

  • 在 Mac 上的 Outlook 中,只有版本 16.35 (20030802) 及更高版本支持保存会议。 否则,从撰写模式下的会议调用时,该 saveAsync 方法将失败。 有关解决方法,请参阅“无法使用 Office JS API 在 Outlook for Mac 中将会议另存为草稿)。

错误

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

示例

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

Office.context.mailbox.item.saveAsync(function (result) {
  if (result.status === Office.AsyncResultStatus.Succeeded) {
    console.log(`saveAsync succeeded, itemId is ${result.value}`);
  }
  else {
    console.error(`saveAsync failed with message ${result.error.message}`);
  }
});

saveAsync(callback)

异步保存项目。

由于约会没有草稿状态,因此,如果在撰写模式下对约会调用,则 saveAsync 项目将在用户日历上另存为普通约会。 对于之前尚未保存的新约会,不会发送邀请。 对于现有约会,将向已添加或已删除的与会者发送更新。

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

参数

callback

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

当该方法完成时,将使用单个参数(一个对象)asyncResultOffice.AsyncResult调用传入参数的callback函数。 在属性中 asyncResult.value 返回 EWS 约会 ID。

返回

void

注解

API 集:邮箱 1.3

最低权限级别读取/写入项目

适用的 Outlook 模式:约会组织者

重要说明

  • 在 Outlook 网页版、新的 Windows 版 Outlook 或处于联机模式 (非缓存模式) 的经典 Windows 版 Outlook 中,项目将保存到服务器。 在 Outlook 缓存模式下,该项目被保存到本地缓存中。

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

  • 返回的标识符与 Exchange Web 服务 (EWS) 项标识符相同。 返回的项 ID 与 Outlook 条目 ID 或 Outlook REST API 使用的 ID 并不完全相同。 在使用此值进行 REST API 调用之前,应使用 Office.context.mailbox.convertToRestId.

  • 如果加载项调用 saveAsync 获取要用于 EWS 或 REST API 的项 ID,请注意,当 Outlook 处于缓存模式时,可能需要一段时间才能将项目实际同步到服务器。 在项同步之前,使用项 ID 将返回错误。

  • 在 Mac 上的 Outlook 中,只有版本 16.35 (20030802) 及更高版本支持保存会议。 否则,从撰写模式下的会议调用时,该 saveAsync 方法将失败。 有关解决方法,请参阅“无法使用 Office JS API 在 Outlook for Mac 中将会议另存为草稿)。

错误

  • 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"
}

sendAsync(options, callback)

发送正在撰写的约会。

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

参数

options
Office.AsyncContextOptions

包含 asyncContext 属性的对象文本。 使用该 asyncContext 属性指定要在回调函数中访问的任何对象。

callback

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

可选。 当该方法完成时,将使用单个参数调用asyncResult传入参数的callback函数。 参数是一个asyncResultOffice.AsyncResult对象。

返回

void

注解

API 集:邮箱 1.15

最低权限级别读/写邮箱

适用的 Outlook 模式:约会组织者

重要说明

  • sendAsync该方法仅在任务窗格和函数命令实现中受支持。 在基于事件的处理程序项多选方案中不支持此功能。

  • 在函数命令实现中,返回 asyncResult.status 的值可能不会反映正在撰写的约会是否已成功发送。 这是因为该 sendAsync 方法是一个异步 API,并且加载项无法控制的事件 (例如,由单独安装的 智能警报加载项 处理的事件) 可能会阻止发送项目。 由于不能依赖返回 asyncResult.status 的状态来运行某些操作,因此应仅调用回调函数中的 event.completed 方法。 event.completed此调用表示加载项已完成处理。 除了此调用之外,不保证回调函数中的其他代码能运行。 建议在调用 sendAsync之前处理其他操作。

  • 在任务窗格实现中,不保证在执行任务Office.AsyncResultStatus.SuccessasyncResult.status运行的任何代码都会得到处理。 这是因为项目可能已经发送,并且加载项已完成处理。 建议在调用 sendAsync之前处理其他操作。

  • 调用后 sendAsync 包括的任何代码都不能保证能运行,因为加载项会在调用后 sendAsync 完成处理。

sendAsync(callback)

发送正在撰写的约会。

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

参数

callback

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

可选。 当该方法完成时,将使用单个参数调用asyncResult传入参数的callback函数。 参数是一个asyncResultOffice.AsyncResult对象。

返回

void

注解

API 集:邮箱 1.15

最低权限级别读/写邮箱

适用的 Outlook 模式:约会组织者

重要说明

  • sendAsync该方法仅在任务窗格和函数命令实现中受支持。 在基于事件的处理程序项多选方案中不支持此功能。

  • 在函数命令实现中,返回 asyncResult.status 的值可能不会反映正在撰写的约会是否已成功发送。 这是因为该 sendAsync 方法是一个异步 API,并且加载项无法控制的事件 (例如,由单独安装的 智能警报加载项 处理的事件) 可能会阻止发送项目。 由于不能依赖返回 asyncResult.status 的状态来运行某些操作,因此应仅调用回调函数中的 event.completed 方法。 event.completed此调用表示加载项已完成处理。 除了此调用之外,不保证回调函数中的其他代码能运行。 建议在调用 sendAsync之前处理其他操作。

  • 在任务窗格实现中,不保证在执行任务Office.AsyncResultStatus.SuccessasyncResult.status运行的任何代码都会得到处理。 这是因为项目可能已经发送,并且加载项已完成处理。 建议在调用 sendAsync之前处理其他操作。

  • 调用后 sendAsync 包括的任何代码都不能保证能运行,因为加载项会在调用后 sendAsync 完成处理。

示例

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

// This snippet sends the current message or appointment being composed.
Office.context.mailbox.item.sendAsync((asyncResult) => {
  if (asyncResult.status === Office.AsyncResultStatus.Failed) {
    console.log("Action failed with error: " + asyncResult.error.message);
    return;
  }
});

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 网页版、Windows () 和经典 以及 Mac 上。 如果字段是 HTML 编辑器,只会插入文本数据,即使数据为 HTML,也不例外。 如果数据是 HTML,并且字段支持 HTML, (主题不) ,则当前样式将应用于 Windows 上的 Outlook 网页版 和新版 Outlook。 默认样式应用于 Windows (经典) 和 Mac 上的 Outlook。 如果该字段是文本字段,则返回 InvalidDataFormat 错误。 如果未设置 coercionType,则结果取决于该字段:如果该字段是 HTML,则使用 HTML;如果该字段是文本,则使用纯文本。

callback

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

可选。 当该方法完成时, callback 将使用类型 Office.AsyncResult为 .

返回

void

注解

API 集:邮箱 1.2

最低权限级别读取/写入项目

适用的 Outlook 模式:约会组织者

错误

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

示例

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

可选。 当该方法完成时, callback 将使用类型 Office.AsyncResult为 .

返回

void

注解

API 集:邮箱 1.2

最低权限级别读取/写入项目

适用的 Outlook 模式:约会组织者

错误

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