Office.AppointmentCompose interface

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

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

父接口:

扩展

属性

body

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

end

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

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

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

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

itemType

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

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

location

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

optionalAttendees

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

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

requiredAttendees

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

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

start

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

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

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

重要提示:在 Windows 客户端中,不能使用此属性来更新重复周期的开始时间。

subject

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

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

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

方法

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。

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 方法可以将项附加到除正在编辑的项外的项;但既不支持也不建议这样做。

loadCustomPropertiesAsync(callback, userContext)

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

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

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

removeAttachmentAsync(attachmentId, options, callback)

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

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

removeAttachmentAsync(attachmentId, callback)

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

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

属性详细信息

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

end

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

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

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

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

end: Time;

属性值

注解

最低权限级别读取项

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

示例

// The following example sets the end time of an appointment in compose mode by
// using the `setAsync` method of the `Time` object.
const endTime = new Date("3/14/2015");
const options = {
    // Pass information that can be used in the callback.
    asyncContext: {verb: "Set"}
};
Office.context.mailbox.item.end.setAsync(endTime, options, function(result) {
    if (result.error) {
        console.debug(result.error);
    } else {
        // Access the asyncContext that was passed to the setAsync method.
        console.debug("End Time " + result.asyncContext.verb);
    }
});
// 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;
  }
  console.log(`Appointment ends: ${result.value}`);
});

...

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

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;

属性值

注解

最低权限级别读取项

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

示例

const userContext = { value : 1 };
Office.context.mailbox.item.location.getAsync( { context: userContext}, callback);

function callback(asyncResult) {
    const context = asyncResult.context;
    const location = asyncResult.value;
}
// 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}`);
});

optionalAttendees

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

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

optionalAttendees: Recipients;

属性值

注解

最低权限级别读取项

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

示例

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

function callback(asyncResult) {
    const arrayOfOptionalAttendeesRecipients = asyncResult.value;
}
// 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 = $("#emailOptional")
  .val()
  .toString();
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);
  }
});

requiredAttendees

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

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

requiredAttendees: Recipients;

属性值

注解

最低权限级别读取项

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

示例

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

function callback(asyncResult) {
    const arrayOfRequiredAttendeesRecipients = asyncResult.value;
    console.log(JSON.stringify(arrayOfRequiredAttendeesRecipients));
}
// 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 = $("#emailRequired")
  .val()
  .toString();
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);
  }
});

start

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

属性start是表示为协调世界时 (UTC) 日期和时间值的 Time 对象。 可以使用 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;
  }
  console.log(`Appointment starts: ${result.value}`);
});

...

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 上载文件并将其附加到撰写窗体中的项目。

随后可以将该标识符与 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:邮件或约会的附件过多。

示例

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

const attachmentUrl = $("#attachmentUrl")
  .val()
  .toString();
Office.context.mailbox.item.addFileAttachmentAsync(
  attachmentUrl,
  getFileName(attachmentUrl),
  { isInline: false },
  (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:邮件或约会的附件过多。

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单个参数调用在回调参数中传递的函数。 如果成功,附件标识符将在 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 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 网页版中运行,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 set: Mailbox 1.1 ]

最低权限级别读/写项

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

错误

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

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 模式:约会组织者

示例

// 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 网页版和移动设备上,附件标识符仅在同一会话中有效。 当用户关闭应用时,会话结束,或者如果用户开始撰写内联窗体,然后弹出窗体以在单独的窗口中继续。

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 模式:约会组织者

重要说明*:该方法 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(
  $("#attachmentId")
    .val()
    .toString(),
  (result) => {
    if (result.status === Office.AsyncResultStatus.Failed) {
      console.error(result.error.message);
      return;
    }

    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 模式:约会组织者

重要说明*:该方法 removeAttachmentAsync 不会从邮件项中删除内联附件。 若要删除内联附件,请先获取项目的正文,然后从其内容中删除附件的任何引用。 使用 Office.Body API 获取和设置项的正文。

错误

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