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.
Remarks
Minimum permission level | ReadItem |
Applicable Outlook mode | Compose or Read |
Methods
get |
Gets a value that indicates whether the content is in HTML or text format. |
get |
Gets a value that indicates whether the content is in HTML or text format. |
get |
Gets a value that indicates whether the content is in HTML or text format. |
prepend |
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 (<a>) to "LPNoLP" (please see the Examples section for a sample). |
prepend |
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 (<a>) to "LPNoLP" (please see the Examples section for a sample). |
prepend |
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 (<a>) to "LPNoLP" (please see the Examples section for a sample). |
set |
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 (<a>) to "LPNoLP" (please see the Examples section for a sample). |
set |
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 (<a>) to "LPNoLP" (please see the Examples section for a sample). |
set |
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 (<a>) to "LPNoLP" (please see the Examples section for a sample). |
Method Details
getTypeAsync(options, callback)
Gets a value that indicates whether the content is in HTML or text format.
getTypeAsync(options?: Office.AsyncContextOptions, callback?: (result: Office.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: Office.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
Remarks
Minimum permission level | ReadItem |
Applicable Outlook mode | Compose |
getTypeAsync(callback)
Gets a value that indicates whether the content is in HTML or text format.
getTypeAsync(callback?: (result: Office.AsyncResult<Office.CoercionType>) => void): void;
Parameters
- callback
- (result: Office.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
Remarks
Minimum permission level | ReadItem |
Applicable Outlook mode | Compose |
Examples
Office.context.mailbox.item.body.getTypeAsync(function (asyncResult) {
if (asyncResult.status === "failed") {
console.log("Action failed with error: " + asyncResult.error.message);
} else {
console.log("Body type: " + asyncResult.value);
}
});
getTypeAsync()
Gets a value that indicates whether the content is in HTML or text format.
getTypeAsync(): void;
Returns
Remarks
Minimum permission level | ReadItem |
Applicable Outlook mode | Compose |
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 (<a>) to "LPNoLP" (please see the Examples section for a sample).
prependAsync(data: string, options?: Office.AsyncContextOptions & CoercionTypeOptions, callback?: (result: Office.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: Office.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
Remarks
Minimum permission level | ReadWriteItem |
Applicable Outlook mode | Compose |
Errors | DataExceedsMaximumSize - The data parameter is longer than 1,000,000 characters. |
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);
prependAsync(data, 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 (<a>) to "LPNoLP" (please see the Examples section for a sample).
prependAsync(data: string, callback: (result: Office.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.
- callback
- (result: Office.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
Remarks
Minimum permission level | ReadWriteItem |
Applicable Outlook mode | Compose |
Errors | DataExceedsMaximumSize - The data parameter is longer than 1,000,000 characters. |
prependAsync(data)
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 (<a>) to "LPNoLP" (please see the Examples section for a sample).
prependAsync(data: string): void;
Parameters
- data
- string
The string to be inserted at the beginning of the body. The string is limited to 1,000,000 characters.
Returns
Remarks
Minimum permission level | ReadWriteItem |
Applicable Outlook mode | Compose |
Errors | DataExceedsMaximumSize - The data parameter is longer than 1,000,000 characters. |
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 (<a>) to "LPNoLP" (please see the Examples section for a sample).
setSelectedDataAsync(data: string, options?: Office.AsyncContextOptions & CoercionTypeOptions, callback?: (result: Office.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: Office.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
Remarks
Minimum permission level | ReadWriteItem |
Applicable Outlook mode | Compose |
Errors | DataExceedsMaximumSize - 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. |
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);
setSelectedDataAsync(data, 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 (<a>) to "LPNoLP" (please see the Examples section for a sample).
setSelectedDataAsync(data: string, callback: (result: Office.AsyncResult<void>) => void): void;
Parameters
- data
- string
The string that will replace the existing body. The string is limited to 1,000,000 characters.
- callback
- (result: Office.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
Remarks
Minimum permission level | ReadWriteItem |
Applicable Outlook mode | Compose |
Errors | DataExceedsMaximumSize - 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. |
setSelectedDataAsync(data)
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 (<a>) to "LPNoLP" (please see the Examples section for a sample).
setSelectedDataAsync(data: string): void;
Parameters
- data
- string
The string that will replace the existing body. The string is limited to 1,000,000 characters.
Returns
Remarks
Minimum permission level | ReadWriteItem |
Applicable Outlook mode | Compose |
Errors | DataExceedsMaximumSize - 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. |
Feedback
We'd love to hear your thoughts. Choose the type you'd like to provide:
Our feedback system is built on GitHub Issues. Read more on our blog.
Loading feedback...