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

getAsync(coerciontype, options, callback)

Returns the current body in a specified format.

This method returns the entire current body in the format specified by coercionType.

When working with HTML-formatted bodies, it is important to note that the Body.getAsync and Body.setAsync methods are not idempotent. The value returned from the getAsync method will not necessarily be exactly the same as the value that was passed in the setAsync method previously. The client may modify the value passed to setAsync in order to make it render efficiently with its rendering engine.

[ API set: Mailbox 1.3 ]

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 ]

setAsync(data, options, callback)

Replaces the entire body with the specified text.

When working with HTML-formatted bodies, it is important to note that the Body.getAsync and Body.setAsync methods are not idempotent. The value returned from the getAsync method will not necessarily be exactly the same as the value that was passed in the setAsync method previously. The client may modify the value passed to setAsync in order to make it render efficiently with its rendering engine.

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.3 ]

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

getAsync(coerciontype, options, callback)

Returns the current body in a specified format.

This method returns the entire current body in the format specified by coercionType.

When working with HTML-formatted bodies, it is important to note that the Body.getAsync and Body.setAsync methods are not idempotent. The value returned from the getAsync method will not necessarily be exactly the same as the value that was passed in the setAsync method previously. The client may modify the value passed to setAsync in order to make it render efficiently with its rendering engine.

[ API set: Mailbox 1.3 ]

getAsync(coerciontype: Office.CoercionType, options?: Office.AsyncContextOptions, callback?: (result: AsyncResult<Office.Body>) => void): void;
Parameters
coerciontype
Office.CoercionType
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<Office.Body>) => void

Optional. When the method completes, the function passed in the callback parameter is called with a single parameter of type AsyncResult. The body is provided in the requested format in the asyncResult.value property.

Returns
void
Remarks
Minimum permission levelReadItem
Applicable Outlook modeCompose or read

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

getAsync(coerciontype: Office.CoercionType, callback: (result: AsyncResult&lt;Office.Body&gt;) => void): void;

Examples

// This example gets the body of the message in 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"
}

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<Office.CoercionType>) => 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<Office.CoercionType>) => void

Optional. When the method completes, the function passed in the callback parameter is called with a single parameter of type Office.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): 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>) => void

Optional. When the method completes, the function passed in the callback parameter is called with a single parameter of type Office.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 &amp; CoercionTypeOptions): void;

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

prependAsync(data: string): void;

Examples

// When including links in HTML markup, you can disable online link preview
// by setting the id attribute on the anchor (<a>) to "LPNoLP".
Office.context.mailbox.item.body.prependAsync(
    '<a id="LPNoLP" href="http://www.contoso.com">Click here!</a>',
    {coercionType: Office.CoercionType.Html},
    callback);

setAsync(data, options, callback)

Replaces the entire body with the specified text.

When working with HTML-formatted bodies, it is important to note that the Body.getAsync and Body.setAsync methods are not idempotent. The value returned from the getAsync method will not necessarily be exactly the same as the value that was passed in the setAsync method previously. The client may modify the value passed to setAsync in order to make it render efficiently with its rendering engine.

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.3 ]

setAsync(data: string, options?: Office.AsyncContextOptions & CoercionTypeOptions, callback?: (result: AsyncResult<void>) => 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>) => void

Optional. When the method completes, the function passed in the callback parameter is called with a single parameter of type Office.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:

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

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

setAsync(data: string): void;

Examples

// When including links in HTML markup, you can disable online link preview
// by setting the id attribute on the anchor (<a>) to "LPNoLP".
Office.context.mailbox.item.body.setAsync(
    '<a id="LPNoLP" href="http://www.contoso.com">Click here!</a>',
    {coercionType: Office.CoercionType.Html},
    callback);
Office.context.mailbox.item.body.setAsync(
    "<b>(replaces all body, including threads you are replying to that may be on the bottom)</b>",
    { coercionType:"html", asyncContext:"This is passed to the callback" },
    function callback(result) {
        // Process the result
});

// The following is an example of the result parameter passed to the callback function.
{
    "value":null,
    "status":"succeeded",
    "asyncContext":"This is passed to the callback"
}

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): 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>) => void

Optional. When the method completes, the function passed in the callback parameter is called with a single parameter of type Office.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 &amp; CoercionTypeOptions): void;

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

setSelectedDataAsync(data: string): void;

Examples

// When including links in HTML markup, you can disable online link preview
// by setting the id attribute on the anchor (<a>) to "LPNoLP".
Office.context.mailbox.item.body.setSelectedDataAsync(
    '<a id="LPNoLP" href="http://www.contoso.com">Click here!</a>',
    {coercionType: Office.CoercionType.Html},
    callback);