Office.MessageCompose interface

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

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

父接口:

扩展

属性

bcc

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

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

body

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

cc

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

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

conversationId

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

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

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

itemType

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

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

notificationMessages

获取项目的通知邮件。

subject

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

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

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

to

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

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

方法

addFileAttachmentAsync(uri, attachmentName, options, callback)

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

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

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

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

addFileAttachmentAsync(uri, attachmentName, callback)

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

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

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

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

addItemAttachmentAsync(itemId, attachmentName, options, callback)

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

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

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

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

addItemAttachmentAsync(itemId, attachmentName, callback)

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

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

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

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

close()

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

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

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

getSelectedDataAsync(coercionType, options, callback)

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

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

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

getSelectedDataAsync(coercionType, callback)

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

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

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

loadCustomPropertiesAsync(callback, userContext)

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

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

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

removeAttachmentAsync(attachmentId, options, callback)

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

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

removeAttachmentAsync(attachmentId, callback)

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

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

saveAsync(options, callback)

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

saveAsync(callback)

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

setSelectedDataAsync(data, options, callback)

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

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

setSelectedDataAsync(data, callback)

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

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

属性详细信息

bcc

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

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

bcc: Recipients;

属性值

注解

[ API set: Mailbox 1.1 ]

最低权限级别读取项

适用的 Outlook 模式:邮件撰写

示例

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

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

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

...

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

body

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

body: Body;

属性值

注解

[ API set: Mailbox 1.1 ]

最低权限级别读取项

适用的 Outlook 模式:邮件撰写

示例

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

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

cc

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

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

cc: Recipients;

属性值

注解

最低权限级别读取项

适用的 Outlook 模式:邮件撰写

示例

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

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

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

...

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

conversationId

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

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

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

conversationId: string;

属性值

string

注解

最低权限级别读取项

适用的 Outlook 模式:邮件撰写

示例

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

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

itemType

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

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

itemType: MailboxEnums.ItemType | string;

属性值

注解

最低权限级别读取项

适用的 Outlook 模式:邮件撰写

示例

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

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

notificationMessages

获取项目的通知邮件。

notificationMessages: NotificationMessages;

属性值

注解

[ API 集:邮箱 1.3 ]

最低权限级别读取项

适用的 Outlook 模式:邮件撰写

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/35-notifications/add-getall-remove.yaml

// Adds a progress indicator to the mail item.
const id = $("#notificationId").val().toString();
const details =
  {
    type: Office.MailboxEnums.ItemNotificationMessageType.ProgressIndicator,
    message: "Progress indicator with id = " + id
  };
Office.context.mailbox.item.notificationMessages.addAsync(id, details, handleResult);

...

// Adds an informational notification to the mail item.
const id = $("#notificationId").val().toString();
const details =
  {
    type: Office.MailboxEnums.ItemNotificationMessageType.InformationalMessage,
    message: "Non-persistent informational notification message with id = " + id,
    icon: "icon1",
    persistent: false
  };
Office.context.mailbox.item.notificationMessages.addAsync(id, details, handleResult);

...

// Adds a persistent information notification to the mail item.
const id = $("#notificationId").val().toString();
const details =
  {
    type: Office.MailboxEnums.ItemNotificationMessageType.InformationalMessage,
    message: "Persistent informational notification message with id = " + id,
    icon: "icon1",
    persistent: true
  };
Office.context.mailbox.item.notificationMessages.addAsync(id, details, handleResult);

...

// Gets all the notification messages and their keys for the current mail item.
Office.context.mailbox.item.notificationMessages.getAllAsync((asyncResult) => {
  if (asyncResult.status === Office.AsyncResultStatus.Failed) {
    console.log(asyncResult.error.message);
    return;
  }

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

...

// Replaces a notification message of a given key with another message.
const id = $("#notificationId").val().toString();
Office.context.mailbox.item.notificationMessages.replaceAsync(
  id,
  {
    type: Office.MailboxEnums.ItemNotificationMessageType.InformationalMessage,
    message: "Notification message with id = " + id + " has been replaced with an informational message.",
    icon: "icon2",
    persistent: false
  },
  handleResult);

...

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

subject

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

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

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

subject: Subject;

属性值

注解

最低权限级别读取项

适用的 Outlook 模式:邮件撰写

示例

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

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

...

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

to

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

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

to: Recipients;

属性值

注解

最低权限级别读取项

适用的 Outlook 模式:邮件撰写

示例

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

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

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

...

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

方法详细信息

addFileAttachmentAsync(uri, attachmentName, options, callback)

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

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

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

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

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

参数

uri

string

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

attachmentName

string

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

options

Office.AsyncContextOptions & { isInline: boolean }

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

callback

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

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

返回

void

注解

[ API set: Mailbox 1.1 ]

最低权限级别读/写项

适用的 Outlook 模式:邮件撰写

错误

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

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

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

示例

// 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单个参数调用在 参数中callback传递的函数。 如果成功,附件标识符将在 asyncResult.value 属性中提供。 如果添加附件失败,asyncResult 对象将包含一个提供错误说明的 Error 对象。

返回

void

注解

[ API set: Mailbox 1.1 ]

最低权限级别读/写项

适用的 Outlook 模式:邮件撰写

错误

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

示例

// The following example adds an existing Outlook item as an attachment
// with the name "My Attachment".
function 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单个参数调用在 参数中callback传递的函数。 如果成功,附件标识符将在 asyncResult.value 属性中提供。 如果添加附件失败,asyncResult 对象将包含一个提供错误说明的 Error 对象。

返回

void

注解

[ API set: Mailbox 1.1 ]

最低权限级别读/写项

适用的 Outlook 模式:邮件撰写

错误

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

close()

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

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

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

close(): void;

返回

void

注解

[ API 集:邮箱 1.3 ]

最低权限级别受限

适用的 Outlook 模式:邮件撰写

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

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

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

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

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

示例

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

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

getSelectedDataAsync(coercionType, options, callback)

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

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

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

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

参数

coercionType

Office.CoercionType | string

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

options
Office.AsyncContextOptions

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

callback

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

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

返回

void

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

注解

[ API set: Mailbox 1.2 ]

最低权限级别读取项

适用的 Outlook 模式:邮件撰写

示例

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

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

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

getSelectedDataAsync(coercionType, callback)

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

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

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

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

参数

coercionType

Office.CoercionType | string

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

callback

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

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

返回

void

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

注解

[ API set: Mailbox 1.2 ]

最低权限级别读取项

适用的 Outlook 模式:邮件撰写

示例

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

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

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:附件标识符不存在。

saveAsync(options, callback)

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

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

参数

options
Office.AsyncContextOptions

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

callback

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

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

返回

void

注解

[ API 集:邮箱 1.3 ]

最低权限级别读/写项

适用的 Outlook 模式:邮件撰写

重要说明

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

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

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

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

错误

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

saveAsync(callback)

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

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

参数

callback

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

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

返回

void

注解

[ API 集:邮箱 1.3 ]

最低权限级别读/写项

适用的 Outlook 模式:邮件撰写

重要说明

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

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

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

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

错误

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

示例

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

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

setSelectedDataAsync(data, options, callback)

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

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

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

参数

data

string

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

options

Office.AsyncContextOptions & Office.CoercionTypeOptions

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

callback

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

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

返回

void

注解

[ API set: Mailbox 1.2 ]

最低权限级别读/写项

适用的 Outlook 模式:邮件撰写

错误

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

示例

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

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

setSelectedDataAsync(data, callback)

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

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

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

参数

data

string

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

callback

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

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

返回

void

注解

[ API set: Mailbox 1.2 ]

最低权限级别读/写项

适用的 Outlook 模式:邮件撰写

错误

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