Office.Body interface

The body object provides methods for adding and updating the content of the message or appointment. It is returned in the body property of the selected item.

[ API set: Mailbox 1.1 ]

Remarks

Minimum permission levelReadItem
Applicable Outlook modeCompose or read

Methods

getTypeAsync(options, callback)

Gets a value that indicates whether the content is in HTML or text format.

[ API set: Mailbox 1.1 ]

prependAsync(data, options, callback)

Adds the specified content to the beginning of the item body.

The prependAsync method inserts the specified string at the beginning of the item body. After insertion, the cursor is returned to its original place, relative to the inserted content.

When including links in HTML markup, you can disable online link preview by setting the id attribute on the anchor () to "LPNoLP" (please see the Examples section for a sample).

[ API set: Mailbox 1.1 ]

setSelectedDataAsync(data, options, callback)

Replaces the selection in the body with the specified text.

The setSelectedDataAsync method inserts the specified string at the cursor location in the body of the item, or, if text is selected in the editor, it replaces the selected text. If the cursor was never in the body of the item, or if the body of the item lost focus in the UI, the string will be inserted at the top of the body content. After insertion, the cursor is placed at the end of the inserted content.

When including links in HTML markup, you can disable online link preview by setting the id attribute on the anchor () to "LPNoLP" (please see the Examples section for a sample).

[ API set: Mailbox 1.1 ]

Method Details

getTypeAsync(options, callback)

Gets a value that indicates whether the content is in HTML or text format.

[ API set: Mailbox 1.1 ]

getTypeAsync(options?: Office.AsyncContextOptions, callback?: (result: AsyncResult) => void): void;
Parameters
options
Office.AsyncContextOptions

Optional. An object literal that contains one or more of the following properties. asyncContext: Developers can provide any object they wish to access in the callback method.

callback
(result: AsyncResult) => void

Optional. When the method completes, the function passed in the callback parameter is called with a single parameter of type AsyncResult. The content type is returned as one of the CoercionType values in the asyncResult.value property.

Returns
void
Remarks
Minimum permission levelReadItem
Applicable Outlook modeCompose

prependAsync(data, options, callback)

Adds the specified content to the beginning of the item body.

The prependAsync method inserts the specified string at the beginning of the item body. After insertion, the cursor is returned to its original place, relative to the inserted content.

When including links in HTML markup, you can disable online link preview by setting the id attribute on the anchor () to "LPNoLP" (please see the Examples section for a sample).

[ API set: Mailbox 1.1 ]

prependAsync(data: string, options?: Office.AsyncContextOptions & CoercionTypeOptions, callback?: (result: AsyncResult) => void): void;
Parameters
data
string

The string to be inserted at the beginning of the body. The string is limited to 1,000,000 characters.

options
Office.AsyncContextOptions & CoercionTypeOptions

Optional. An object literal that contains one or more of the following properties. asyncContext: Developers can provide any object they wish to access in the callback method. coercionType: The desired format for the body. The string in the data parameter will be converted to this format.

callback
(result: AsyncResult) => void

Optional. When the method completes, the function passed in the callback parameter is called with a single parameter of type AsyncResult. Any errors encountered will be provided in the asyncResult.error property.

Returns
void
Remarks
Minimum permission levelReadWriteItem
Applicable Outlook modeCompose
ErrorsDataExceedsMaximumSize - The data parameter is longer than 1,000,000 characters.

In addition to the main signature, this method also has these signatures:

prependAsync(data: string, options: Office.AsyncContextOptions & CoercionTypeOptions): void;

prependAsync(data: string, callback: (result: AsyncResult) => void): void;

prependAsync(data: string): void;

setSelectedDataAsync(data, options, callback)

Replaces the selection in the body with the specified text.

The setSelectedDataAsync method inserts the specified string at the cursor location in the body of the item, or, if text is selected in the editor, it replaces the selected text. If the cursor was never in the body of the item, or if the body of the item lost focus in the UI, the string will be inserted at the top of the body content. After insertion, the cursor is placed at the end of the inserted content.

When including links in HTML markup, you can disable online link preview by setting the id attribute on the anchor () to "LPNoLP" (please see the Examples section for a sample).

[ API set: Mailbox 1.1 ]

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

The string that will replace the existing body. The string is limited to 1,000,000 characters.

options
Office.AsyncContextOptions & CoercionTypeOptions

Optional. An object literal that contains one or more of the following properties. asyncContext: Developers can provide any object they wish to access in the callback method. coercionType: The desired format for the body. The string in the data parameter will be converted to this format.

callback
(result: AsyncResult) => void

Optional. When the method completes, the function passed in the callback parameter is called with a single parameter of type AsyncResult. Any errors encountered will be provided in the asyncResult.error property.

Returns
void
Remarks
Minimum permission levelReadWriteItem
Applicable Outlook modeCompose
ErrorsDataExceedsMaximumSize - The data parameter is longer than 1,000,000 characters.
InvalidFormatError - The options.coercionType parameter is set to Office.CoercionType.Html and the message body is in plain text.

In addition to the main signature, this method also has these signatures:

setSelectedDataAsync(data: string, options: Office.AsyncContextOptions & CoercionTypeOptions): void;

setSelectedDataAsync(data: string, callback: (result: AsyncResult) => void): void;

setSelectedDataAsync(data: string): void;