Office.MessageCompose interface

The message compose mode of Office.context.mailbox.item.

Important: This is an internal Outlook object, not directly exposed through existing interfaces. You should treat this as a mode of Office.context.mailbox.item. Refer to the Object Model page for more information.

Parent interfaces:

Extends

Properties

bcc

Gets an object that provides methods to get or update the recipients on the Bcc (blind carbon copy) line of a message.

By default, the collection is limited to a maximum of 100 members. However, on Windows and Mac, the following limits apply.

  • Get 500 members maximum.

  • Set a maximum of 100 members per call, up to 500 members total.

[ API set: Mailbox 1.1 ]

body

Gets an object that provides methods for manipulating the body of an item.

[ API set: Mailbox 1.1 ]

categories

Gets an object that provides methods for managing the item's categories.

[ API set: Mailbox 1.8 ]

cc

Provides access to the Cc (carbon copy) recipients of a message. The type of object and level of access depends on the mode of the current item.

The cc property returns a Recipients object that provides methods to get or update the recipients on the Cc line of the message. By default, the collection is limited to a maximum of 100 members. However, on Windows and Mac, the following limits apply.

  • Get 500 members maximum.

  • Set a maximum of 100 members per call, up to 500 members total.

conversationId

Gets an identifier for the email conversation that contains a particular message.

You can get an integer for this property if your mail app is activated in read forms or responses in compose forms. If subsequently the user changes the subject of the reply message, upon sending the reply, the conversation ID for that message will change and that value you obtained earlier will no longer apply.

You get null for this property for a new item in a compose form. If the user sets a subject and saves the item, the conversationId property will return a value.

from

Gets the email address of the sender of a message.

The from and sender properties represent the same person unless the message is sent by a delegate. In that case, the from property represents the owner, and the sender property represents the delegate.

The from property returns a From object that provides a method to get the from value.

[ API set: Mailbox 1.7 ]

internetHeaders

Gets or sets the custom internet headers of a message.

The internetHeaders property returns an InternetHeaders object that provides methods to manage the internet headers on the message.

[ API set: Mailbox 1.8 ]

itemType

Gets the type of item that an instance represents.

The itemType property returns one of the ItemType enumeration values, indicating whether the item object instance is a message or an appointment.

notificationMessages

Gets the notification messages for an item.

[ API set: Mailbox 1.3 ]

seriesId

Gets the id of the series that an instance belongs to.

In Outlook on the web and desktop clients, the seriesId returns the Exchange Web Services (EWS) ID of the parent (series) item that this item belongs to. However, on iOS and Android, the seriesId returns the REST ID of the parent item.

Note: The identifier returned by the seriesId property is the same as the Exchange Web Services item identifier. The seriesId property is not identical to the Outlook IDs used by the Outlook REST API. Before making REST API calls using this value, it should be converted using Office.context.mailbox.convertToRestId. For more details, see Use the Outlook REST APIs from an Outlook add-in.

The seriesId property returns null for items that do not have parent items such as single appointments, series items, or meeting requests and returns undefined for any other items that are not meeting requests.

[ API set: Mailbox 1.7 ]

subject

Gets or sets the description that appears in the subject field of an item.

The subject property gets or sets the entire subject of the item, as sent by the email server.

The subject property returns a Subject object that provides methods to get and set the subject.

to

Provides access to the recipients on the To line of a message. The type of object and level of access depends on the mode of the current item.

The to property returns a Recipients object that provides methods to get or update the recipients on the To line of the message. By default, the collection is limited to a maximum of 100 members. However, on Windows and Mac, the following limits apply.

  • Get 500 members maximum.

  • Set a maximum of 100 members per call, up to 500 members total.

Methods

addFileAttachmentAsync(uri, attachmentName, options, callback)

Adds a file to a message or appointment as an attachment.

The addFileAttachmentAsync method uploads the file at the specified URI and attaches it to the item in the compose form.

You can subsequently use the identifier with the removeAttachmentAsync method to remove the attachment in the same session.

Important: In recent builds of Outlook on Windows, a bug was introduced that incorrectly appends an Authorization: Bearer header to this action (whether using this API or the Outlook UI). To work around this issue, you can try using the addFileAttachmentFromBase64 API introduced with requirement set 1.8.

[ API set: Mailbox 1.1 ]

addFileAttachmentAsync(uri, attachmentName, callback)

Adds a file to a message or appointment as an attachment.

The addFileAttachmentAsync method uploads the file at the specified URI and attaches it to the item in the compose form.

You can subsequently use the identifier with the removeAttachmentAsync method to remove the attachment in the same session.

Important: In recent builds of Outlook on Windows, a bug was introduced that incorrectly appends an Authorization: Bearer header to this action (whether using this API or the Outlook UI). To work around this issue, you can try using the addFileAttachmentFromBase64 API introduced with requirement set 1.8.

[ API set: Mailbox 1.1 ]

addFileAttachmentFromBase64Async(base64File, attachmentName, options, callback)

Adds a file to a message or appointment as an attachment.

The addFileAttachmentFromBase64Async method uploads the file from the base64 encoding and attaches it to the item in the compose form. This method returns the attachment identifier in the asyncResult.value object.

You can subsequently use the identifier with the removeAttachmentAsync method to remove the attachment in the same session.

Note: If you're using a data URL API (e.g., readAsDataURL), you need to strip out the data URL prefix then send the rest of the string to this API. For example, if the full string is represented by data:image/svg+xml;base64,<rest of base64 string>, remove data:image/svg+xml;base64,.

[ API set: Mailbox 1.8 ]

addFileAttachmentFromBase64Async(base64File, attachmentName, callback)

Adds a file to a message or appointment as an attachment.

The addFileAttachmentFromBase64Async method uploads the file from the base64 encoding and attaches it to the item in the compose form. This method returns the attachment identifier in the asyncResult.value object.

You can subsequently use the identifier with the removeAttachmentAsync method to remove the attachment in the same session.

Note: If you're using a data URL API (e.g., readAsDataURL), you need to strip out the data URL prefix then send the rest of the string to this API. For example, if the full string is represented by data:image/svg+xml;base64,<rest of base64 string>, remove data:image/svg+xml;base64,.

[ API set: Mailbox 1.8 ]

addHandlerAsync(eventType, handler, options, callback)

Adds an event handler for a supported event. Note: Events are available only with task pane.

To see which event types are supported, see Office.EventType for details.

[ API set: Mailbox 1.7 ]

addHandlerAsync(eventType, handler, callback)

Adds an event handler for a supported event. Note: Events are available only with task pane.

To see which event types are supported, see Office.EventType for details.

[ API set: Mailbox 1.7 ]

addItemAttachmentAsync(itemId, attachmentName, options, callback)

Adds an Exchange item, such as a message, as an attachment to the message or appointment.

The addItemAttachmentAsync method attaches the item with the specified Exchange identifier to the item in the compose form. If you specify a callback method, the method is called with one parameter, asyncResult, which contains either the attachment identifier or a code that indicates any error that occurred while attaching the item. You can use the options parameter to pass state information to the callback method, if needed.

You can subsequently use the identifier with the removeAttachmentAsync method to remove the attachment in the same session.

If your Office add-in is running in Outlook on the web, the addItemAttachmentAsync method can attach items to items other than the item that you are editing; however, this is not supported and is not recommended.

[ API set: Mailbox 1.1 ]

addItemAttachmentAsync(itemId, attachmentName, callback)

Adds an Exchange item, such as a message, as an attachment to the message or appointment.

The addItemAttachmentAsync method attaches the item with the specified Exchange identifier to the item in the compose form. If you specify a callback method, the method is called with one parameter, asyncResult, which contains either the attachment identifier or a code that indicates any error that occurred while attaching the item. You can use the options parameter to pass state information to the callback method, if needed.

You can subsequently use the identifier with the removeAttachmentAsync method to remove the attachment in the same session.

If your Office add-in is running in Outlook on the web, the addItemAttachmentAsync method can attach items to items other than the item that you are editing; however, this is not supported and is not recommended.

[ API set: Mailbox 1.1 ]

close()

Closes the current item that is being composed

The behaviors of the close method depends on the current state of the item being composed. If the item has unsaved changes, the client prompts the user to save, discard, or close the action.

In the Outlook desktop client, if the message is an inline reply, the close method has no effect.

Note: In Outlook on the web, if the item is an appointment and it has previously been saved using saveAsync, the user is prompted to save, discard, or cancel even if no changes have occurred since the item was last saved.

[ API set: Mailbox 1.3 ]

getAttachmentContentAsync(attachmentId, options, callback)

Gets an attachment from a message or appointment and returns it as an AttachmentContent object.

The getAttachmentContentAsync method gets the attachment with the specified identifier from the item. As a best practice, you should use the identifier to retrieve an attachment in the same session that the attachmentIds were retrieved with the getAttachmentsAsync or item.attachments call. In Outlook on the web and mobile devices, the attachment identifier is valid only within the same session. A session is over when the user closes the app, or if the user starts composing an inline form then subsequently pops out the form to continue in a separate window.

[ API set: Mailbox 1.8 ]

getAttachmentContentAsync(attachmentId, callback)

Gets an attachment from a message or appointment and returns it as an AttachmentContent object.

The getAttachmentContentAsync method gets the attachment with the specified identifier from the item. As a best practice, you should use the identifier to retrieve an attachment in the same session that the attachmentIds were retrieved with the getAttachmentsAsync or item.attachments call. In Outlook on the web and mobile devices, the attachment identifier is valid only within the same session. A session is over when the user closes the app, or if the user starts composing an inline form then subsequently pops out the form to continue in a separate window.

[ API set: Mailbox 1.8 ]

getAttachmentsAsync(options, callback)

Gets the item's attachments as an array.

[ API set: Mailbox 1.8 ]

getAttachmentsAsync(callback)

Gets the item's attachments as an array.

[ API set: Mailbox 1.8 ]

getItemIdAsync(options, callback)

Asynchronously gets the ID of a saved item.

When invoked, this method returns the item ID via the callback method.

Note: If your add-in calls getItemIdAsync on an item in compose mode (e.g., to get an itemId to use with EWS or the REST API), be aware that when Outlook is in cached mode, it may take some time before the item is synced to the server. Until the item is synced, the itemId is not recognized and using it returns an error.

[ API set: Mailbox 1.8 ]

getItemIdAsync(callback)

Asynchronously gets the ID of a saved item.

When invoked, this method returns the item ID via the callback method.

Note: If your add-in calls getItemIdAsync on an item in compose mode (e.g., to get an itemId to use with EWS or the REST API), be aware that when Outlook is in cached mode, it may take some time before the item is synced to the server. Until the item is synced, the itemId is not recognized and using it returns an error.

[ API set: Mailbox 1.8 ]

getSelectedDataAsync(coercionType, options, callback)

Asynchronously returns selected data from the subject or body of a message.

If there is no selection but the cursor is in the body or subject, the method returns an empty string for the selected data. If a field other than the body or subject is selected, the method returns the InvalidSelection error.

To access the selected data from the callback method, call asyncResult.value.data. To access the source property that the selection comes from, call asyncResult.value.sourceProperty, which will be either body or subject.

[ API set: Mailbox 1.2 ]

getSelectedDataAsync(coercionType, callback)

Asynchronously returns selected data from the subject or body of a message.

If there is no selection but the cursor is in the body or subject, the method returns an empty string for the selected data. If a field other than the body or subject is selected, the method returns the InvalidSelection error.

To access the selected data from the callback method, call asyncResult.value.data. To access the source property that the selection comes from, call asyncResult.value.sourceProperty, which will be either body or subject.

[ API set: Mailbox 1.2 ]

getSharedPropertiesAsync(options, callback)

Gets the properties of an appointment or message in a shared folder, calendar, or mailbox.

Note: This method is not supported in Outlook on Mac, iOS, or Android.

[ API set: Mailbox 1.8 ]

getSharedPropertiesAsync(callback)

Gets the properties of an appointment or message in a shared folder, calendar, or mailbox.

Note: This method is not supported in Outlook on Mac, iOS, or Android.

[ API set: Mailbox 1.8 ]

loadCustomPropertiesAsync(callback, userContext)

Asynchronously loads custom properties for this add-in on the selected item.

Custom properties are stored as key/value pairs on a per-app, per-item basis. This method returns a CustomProperties object in the callback, which provides methods to access the custom properties specific to the current item and the current add-in. Custom properties are not encrypted on the item, so this should not be used as secure storage.

The custom properties are provided as a CustomProperties object in the asyncResult.value property. This object can be used to get, set, and remove custom properties from the item and save changes to the custom property set back to the server.

removeAttachmentAsync(attachmentId, options, callback)

Removes an attachment from a message or appointment.

The removeAttachmentAsync method removes the attachment with the specified identifier from the item. As a best practice, you should use the attachment identifier to remove an attachment only if the same mail app has added that attachment in the same session. In Outlook on the web and mobile devices, the attachment identifier is valid only within the same session. A session is over when the user closes the app, or if the user starts composing an inline form then subsequently pops out the form to continue in a separate window.

[ API set: Mailbox 1.1 ]

removeAttachmentAsync(attachmentId, callback)

Removes an attachment from a message or appointment.

The removeAttachmentAsync method removes the attachment with the specified identifier from the item. As a best practice, you should use the attachment identifier to remove an attachment only if the same mail app has added that attachment in the same session. In Outlook on the web and mobile devices, the attachment identifier is valid only within the same session. A session is over when the user closes the app, or if the user starts composing an inline form then subsequently pops out the form to continue in a separate window.

[ API set: Mailbox 1.1 ]

removeHandlerAsync(eventType, options, callback)

Removes the event handlers for a supported event type. Note: Events are available only with task pane.

To see which event types are supported, see Office.EventType for details.

[ API set: Mailbox 1.7 ]

removeHandlerAsync(eventType, callback)

Removes the event handlers for a supported event type. Note: Events are available only with task pane.

To see which event types are supported, see Office.EventType for details.

[ API set: Mailbox 1.7 ]

saveAsync(options, callback)

Asynchronously saves an item.

When invoked, this method saves the current message as a draft and returns the item id via the callback method. In Outlook on the web or Outlook in online mode, the item is saved to the server. In Outlook in cached mode, the item is saved to the local cache.

Since appointments have no draft state, if saveAsync is called on an appointment in compose mode, the item will be saved as a normal appointment on the user's calendar. For new appointments that have not been saved before, no invitation will be sent. Saving an existing appointment will send an update to added or removed attendees.

Note: If your add-in calls saveAsync on an item in compose mode in order to get an itemId to use with EWS or the REST API, be aware that when Outlook is in cached mode, it may take some time before the item is actually synced to the server. Until the item is synced, using the itemId will return an error.

Note: The following clients have different behavior for saveAsync on appointments in compose mode:

[ API set: Mailbox 1.3 ]

saveAsync(callback)

Asynchronously saves an item.

When invoked, this method saves the current message as a draft and returns the item id via the callback method. In Outlook on the web or Outlook in online mode, the item is saved to the server. In Outlook in cached mode, the item is saved to the local cache.

Since appointments have no draft state, if saveAsync is called on an appointment in compose mode, the item will be saved as a normal appointment on the user's calendar. For new appointments that have not been saved before, no invitation will be sent. Saving an existing appointment will send an update to added or removed attendees.

Note: If your add-in calls saveAsync on an item in compose mode in order to get an itemId to use with EWS or the REST API, be aware that when Outlook is in cached mode, it may take some time before the item is actually synced to the server. Until the item is synced, using the itemId will return an error.

Note: The following clients have different behavior for saveAsync on appointments in compose mode:

[ API set: Mailbox 1.3 ]

setSelectedDataAsync(data, options, callback)

Asynchronously inserts data into the body or subject of a message.

The setSelectedDataAsync method inserts the specified string at the cursor location in the subject or body of the item, or, if text is selected in the editor, it replaces the selected text. If the cursor is not in the body or subject field, an error is returned. After insertion, the cursor is placed at the end of the inserted content.

[ API set: Mailbox 1.2 ]

setSelectedDataAsync(data, callback)

Asynchronously inserts data into the body or subject of a message.

The setSelectedDataAsync method inserts the specified string at the cursor location in the subject or body of the item, or, if text is selected in the editor, it replaces the selected text. If the cursor is not in the body or subject field, an error is returned. After insertion, the cursor is placed at the end of the inserted content.

[ API set: Mailbox 1.2 ]

Property Details

bcc

Gets an object that provides methods to get or update the recipients on the Bcc (blind carbon copy) line of a message.

By default, the collection is limited to a maximum of 100 members. However, on Windows and Mac, the following limits apply.

  • Get 500 members maximum.

  • Set a maximum of 100 members per call, up to 500 members total.

[ API set: Mailbox 1.1 ]

bcc: Recipients;

Property Value

Remarks

Minimum permission level: ReadItem

Applicable Outlook mode: Message Compose

Examples

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) {
    var arrayOfBccRecipients = asyncResult.value;
}

body

Gets an object that provides methods for manipulating the body of an item.

[ API set: Mailbox 1.1 ]

body: Body;

Property Value

Remarks

Minimum permission level: ReadItem

Applicable Outlook mode: Message Compose

Examples

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

categories

Gets an object that provides methods for managing the item's categories.

[ API set: Mailbox 1.8 ]

categories: Categories;

Property Value

Remarks

Minimum permission level: ReadItem

Applicable Outlook mode: Message Compose

Examples

Office.context.mailbox.item.categories.getAsync(function (asyncResult) {
    if (asyncResult.status === Office.AsyncResultStatus.Failed) {
        console.log("Action failed with error: " + asyncResult.error.message);
    } else {
        console.log("Categories: " + JSON.stringify(asyncResult.value));
    }
});

cc

Provides access to the Cc (carbon copy) recipients of a message. The type of object and level of access depends on the mode of the current item.

The cc property returns a Recipients object that provides methods to get or update the recipients on the Cc line of the message. By default, the collection is limited to a maximum of 100 members. However, on Windows and Mac, the following limits apply.

  • Get 500 members maximum.

  • Set a maximum of 100 members per call, up to 500 members total.

cc: Recipients;

Property Value

Remarks

Minimum permission level: ReadItem

Applicable Outlook mode: Message Compose

Examples

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) {
    var arrayOfCcRecipients = asyncResult.value;
}

conversationId

Gets an identifier for the email conversation that contains a particular message.

You can get an integer for this property if your mail app is activated in read forms or responses in compose forms. If subsequently the user changes the subject of the reply message, upon sending the reply, the conversation ID for that message will change and that value you obtained earlier will no longer apply.

You get null for this property for a new item in a compose form. If the user sets a subject and saves the item, the conversationId property will return a value.

conversationId: string;

Property Value

string

Remarks

Minimum permission level: ReadItem

Applicable Outlook mode: Message Compose

Examples

var conversationId = Office.context.mailbox.item.conversationId;
console.log("conversationId: " + conversationId);

from

Gets the email address of the sender of a message.

The from and sender properties represent the same person unless the message is sent by a delegate. In that case, the from property represents the owner, and the sender property represents the delegate.

The from property returns a From object that provides a method to get the from value.

[ API set: Mailbox 1.7 ]

from: From;

Property Value

Remarks

Minimum permission level: ReadItem

Applicable Outlook mode: Message Compose

Examples

Office.context.mailbox.item.from.getAsync(callback);

function callback(asyncResult) {
    var from = asyncResult.value;
}

internetHeaders

Gets or sets the custom internet headers of a message.

The internetHeaders property returns an InternetHeaders object that provides methods to manage the internet headers on the message.

[ API set: Mailbox 1.8 ]

internetHeaders: InternetHeaders;

Property Value

Remarks

Minimum permission level: ReadItem

Applicable Outlook mode: Message Compose

Examples

Office.context.mailbox.item.internetHeaders.getAsync(["header1", "header2"], callback);

function callback(asyncResult) {
    var dictionary = asyncResult.value;
    var header1_value = dictionary["header1"];
}

itemType

Gets the type of item that an instance represents.

The itemType property returns one of the ItemType enumeration values, indicating whether the item object instance is a message or an appointment.

itemType: MailboxEnums.ItemType | string;

Property Value

Remarks

Minimum permission level: ReadItem

Applicable Outlook mode: Message Compose

Examples

if (Office.context.mailbox.item.itemType === Office.MailboxEnums.ItemType.Message) {
    // Do something.
} else {
    // Do something else.
}

notificationMessages

Gets the notification messages for an item.

[ API set: Mailbox 1.3 ]

notificationMessages: NotificationMessages;

Property Value

Remarks

Minimum permission level: ReadItem

Applicable Outlook mode: Message Compose

Examples

// Get all notifications.
Office.context.mailbox.item.notificationMessages.getAllAsync(
    function (asyncResult) {
        console.log(JSON.stringify(asyncResult));
    }
);

seriesId

Gets the id of the series that an instance belongs to.

In Outlook on the web and desktop clients, the seriesId returns the Exchange Web Services (EWS) ID of the parent (series) item that this item belongs to. However, on iOS and Android, the seriesId returns the REST ID of the parent item.

Note: The identifier returned by the seriesId property is the same as the Exchange Web Services item identifier. The seriesId property is not identical to the Outlook IDs used by the Outlook REST API. Before making REST API calls using this value, it should be converted using Office.context.mailbox.convertToRestId. For more details, see Use the Outlook REST APIs from an Outlook add-in.

The seriesId property returns null for items that do not have parent items such as single appointments, series items, or meeting requests and returns undefined for any other items that are not meeting requests.

[ API set: Mailbox 1.7 ]

seriesId: string;

Property Value

string

Remarks

Minimum permission level: ReadItem

Applicable Outlook mode: Message Compose

Examples

var seriesId = Office.context.mailbox.item.seriesId;

// The seriesId property returns null for items that do
// not have parent items (such as single appointments,
// series items, or meeting requests) and returns
// undefined for messages that are not meeting requests.
var isSeriesInstance = (seriesId != null);
console.log("SeriesId is " + seriesId 
    + " and isSeriesInstance is " + isSeriesInstance);

subject

Gets or sets the description that appears in the subject field of an item.

The subject property gets or sets the entire subject of the item, as sent by the email server.

The subject property returns a Subject object that provides methods to get and set the subject.

subject: Subject;

Property Value

Remarks

Minimum permission level: ReadItem

Applicable Outlook mode: Message Compose

Examples

Office.context.mailbox.item.subject.getAsync(callback);

function callback(asyncResult) {
    var subject = asyncResult.value;
}

to

Provides access to the recipients on the To line of a message. The type of object and level of access depends on the mode of the current item.

The to property returns a Recipients object that provides methods to get or update the recipients on the To line of the message. By default, the collection is limited to a maximum of 100 members. However, on Windows and Mac, the following limits apply.

  • Get 500 members maximum.

  • Set a maximum of 100 members per call, up to 500 members total.

to: Recipients;

Property Value

Remarks

Minimum permission level: ReadItem

Applicable Outlook mode: Message Compose

Examples

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) {
    var arrayOfToRecipients = asyncResult.value;
}

Method Details

addFileAttachmentAsync(uri, attachmentName, options, callback)

Adds a file to a message or appointment as an attachment.

The addFileAttachmentAsync method uploads the file at the specified URI and attaches it to the item in the compose form.

You can subsequently use the identifier with the removeAttachmentAsync method to remove the attachment in the same session.

Important: In recent builds of Outlook on Windows, a bug was introduced that incorrectly appends an Authorization: Bearer header to this action (whether using this API or the Outlook UI). To work around this issue, you can try using the addFileAttachmentFromBase64 API introduced with requirement set 1.8.

[ API set: Mailbox 1.1 ]

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

Parameters

uri
string

The URI that provides the location of the file to attach to the message or appointment. The maximum length is 2048 characters.

attachmentName
string

The name of the attachment that is shown while the attachment is uploading. The maximum length is 255 characters.

options
Office.AsyncContextOptions & { isInline: boolean }

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. isInline: If true, indicates that the attachment will be shown inline in the message body, and should not be displayed in the attachment list.

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

Optional. When the method completes, the function passed in the callback parameter is called with a single parameter of type Office.AsyncResult. On success, the attachment identifier will be provided in the asyncResult.value property. If uploading the attachment fails, the asyncResult object will contain an Error object that provides a description of the error.

Returns

void

Remarks

Minimum permission level: ReadWriteItem

Applicable Outlook mode: Message Compose

Errors:

  • AttachmentSizeExceeded: The attachment is larger than allowed.

  • FileTypeNotSupported: The attachment has an extension that is not allowed.

  • NumberOfAttachmentsExceeded: The message or appointment has too many attachments.

Examples

function callback(result) {
    if (result.error) {
        console.log(result.error);
    } else {
        console.log("Attachment added");
    }
}

function addAttachment() {
    // The values in asyncContext can be accessed in the callback.
    var options = { 'asyncContext': { var1: 1, var2: 2 } };

    var attachmentURL = "https://contoso.com/rtm/icon.png";
    Office.context.mailbox.item.addFileAttachmentAsync(attachmentURL, attachmentURL, options, callback);
}
// The following example adds an image file as an inline attachment and
// references the attachment in the message body.
Office.context.mailbox.item.addFileAttachmentAsync(
    "http://i.imgur.com/WJXklif.png",
    "cute_bird.png",
    {
        isInline: true
    },
    function (asyncResult) {
        Office.context.mailbox.item.body.setAsync(
            "<p>Here's a cute bird!</p><img src='cid:cute_bird.png'>",
            {
                "coercionType": "html"
            },
            function (asyncResult) {
                // Do something here.
            });
    });

addFileAttachmentAsync(uri, attachmentName, callback)

Adds a file to a message or appointment as an attachment.

The addFileAttachmentAsync method uploads the file at the specified URI and attaches it to the item in the compose form.

You can subsequently use the identifier with the removeAttachmentAsync method to remove the attachment in the same session.

Important: In recent builds of Outlook on Windows, a bug was introduced that incorrectly appends an Authorization: Bearer header to this action (whether using this API or the Outlook UI). To work around this issue, you can try using the addFileAttachmentFromBase64 API introduced with requirement set 1.8.

[ API set: Mailbox 1.1 ]

addFileAttachmentAsync(uri: string, attachmentName: string, callback?: (asyncResult: Office.AsyncResult<string>) => void): void;

Parameters

uri
string

The URI that provides the location of the file to attach to the message or appointment. The maximum length is 2048 characters.

attachmentName
string

The name of the attachment that is shown while the attachment is uploading. The maximum length is 255 characters.

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

Optional. When the method completes, the function passed in the callback parameter is called with a single parameter of type Office.AsyncResult. On success, the attachment identifier will be provided in the asyncResult.value property. If uploading the attachment fails, the asyncResult object will contain an Error object that provides a description of the error.

Returns

void

Remarks

Minimum permission level: ReadWriteItem

Applicable Outlook mode: Message Compose

Errors:

  • AttachmentSizeExceeded: The attachment is larger than allowed.

  • FileTypeNotSupported: The attachment has an extension that is not allowed.

  • NumberOfAttachmentsExceeded: The message or appointment has too many attachments.

addFileAttachmentFromBase64Async(base64File, attachmentName, options, callback)

Adds a file to a message or appointment as an attachment.

The addFileAttachmentFromBase64Async method uploads the file from the base64 encoding and attaches it to the item in the compose form. This method returns the attachment identifier in the asyncResult.value object.

You can subsequently use the identifier with the removeAttachmentAsync method to remove the attachment in the same session.

Note: If you're using a data URL API (e.g., readAsDataURL), you need to strip out the data URL prefix then send the rest of the string to this API. For example, if the full string is represented by data:image/svg+xml;base64,<rest of base64 string>, remove data:image/svg+xml;base64,.

[ API set: Mailbox 1.8 ]

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

Parameters

base64File
string

The base64 encoded content of an image or file to be added to an email or event.

attachmentName
string

The name of the attachment that is shown while the attachment is uploading. The maximum length is 255 characters.

options
Office.AsyncContextOptions & { isInline: boolean }

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. isInline: If true, indicates that the attachment will be shown inline in the message body and should not be displayed in the attachment list.

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

Optional. When the method completes, the function passed in the callback parameter is called with a single parameter of type Office.AsyncResult. On success, the attachment identifier will be provided in the asyncResult.value property. If uploading the attachment fails, the asyncResult object will contain an Error object that provides a description of the error.

Returns

void

Remarks

Minimum permission level: ReadWriteItem

Applicable Outlook mode: Message Compose

Errors:

  • AttachmentSizeExceeded: The attachment is larger than allowed.

  • FileTypeNotSupported: The attachment has an extension that is not allowed.

  • NumberOfAttachmentsExceeded: The message or appointment has too many attachments.

Examples

Office.context.mailbox.item.addFileAttachmentFromBase64Async(
    base64String,
    "cute_bird.png",
    {
        isInline: true
    },
    function (asyncResult) {
        Office.context.mailbox.item.body.setAsync(
            "<p>Here's a cute bird!</p><img src='cid:cute_bird.png'>",
            {
                "coercionType": "html"
            },
            function (asyncResult) {
                // Do something here.
            });
    });

addFileAttachmentFromBase64Async(base64File, attachmentName, callback)

Adds a file to a message or appointment as an attachment.

The addFileAttachmentFromBase64Async method uploads the file from the base64 encoding and attaches it to the item in the compose form. This method returns the attachment identifier in the asyncResult.value object.

You can subsequently use the identifier with the removeAttachmentAsync method to remove the attachment in the same session.

Note: If you're using a data URL API (e.g., readAsDataURL), you need to strip out the data URL prefix then send the rest of the string to this API. For example, if the full string is represented by data:image/svg+xml;base64,<rest of base64 string>, remove data:image/svg+xml;base64,.

[ API set: Mailbox 1.8 ]

addFileAttachmentFromBase64Async(base64File: string, attachmentName: string, callback?: (asyncResult: Office.AsyncResult<string>) => void): void;

Parameters

base64File
string

The base64 encoded content of an image or file to be added to an email or event.

attachmentName
string

The name of the attachment that is shown while the attachment is uploading. The maximum length is 255 characters.

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

Optional. When the method completes, the function passed in the callback parameter is called with a single parameter of type Office.AsyncResult. On success, the attachment identifier will be provided in the asyncResult.value property. If uploading the attachment fails, the asyncResult object will contain an Error object that provides a description of the error.

Returns

void

Remarks

Minimum permission level: ReadWriteItem

Applicable Outlook mode: Message Compose

Errors:

  • AttachmentSizeExceeded: The attachment is larger than allowed.

  • FileTypeNotSupported: The attachment has an extension that is not allowed.

  • NumberOfAttachmentsExceeded: The message or appointment has too many attachments.

addHandlerAsync(eventType, handler, options, callback)

Adds an event handler for a supported event. Note: Events are available only with task pane.

To see which event types are supported, see Office.EventType for details.

[ API set: Mailbox 1.7 ]

addHandlerAsync(eventType: Office.EventType | string, handler: any, options?: Office.AsyncContextOptions, callback?: (asyncResult: Office.AsyncResult<void>) => void): void;

Parameters

eventType
Office.EventType | string

The event that should invoke the handler.

handler
any

The function to handle the event. The function must accept a single parameter, which is an object literal. The type property on the parameter will match the eventType parameter passed to addHandlerAsync.

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
(asyncResult: Office.AsyncResult<void>) => void

Optional. When the method completes, the function passed in the callback parameter is called with a single parameter, asyncResult, which is an Office.AsyncResult object.

Returns

void

Remarks

Minimum permission level: ReadItem

Applicable Outlook mode: Message Compose

addHandlerAsync(eventType, handler, callback)

Adds an event handler for a supported event. Note: Events are available only with task pane.

To see which event types are supported, see Office.EventType for details.

[ API set: Mailbox 1.7 ]

addHandlerAsync(eventType: Office.EventType | string, handler: any, callback?: (asyncResult: Office.AsyncResult<void>) => void): void;

Parameters

eventType
Office.EventType | string

The event that should invoke the handler.

handler
any

The function to handle the event. The function must accept a single parameter, which is an object literal. The type property on the parameter will match the eventType parameter passed to addHandlerAsync.

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

Optional. When the method completes, the function passed in the callback parameter is called with a single parameter, asyncResult, which is an Office.AsyncResult object.

Returns

void

Remarks

Minimum permission level: ReadItem

Applicable Outlook mode: Message Compose

Examples

function myHandlerFunction(eventarg) {
    if (eventarg.attachmentStatus === Office.MailboxEnums.AttachmentStatus.Added) {
        var attachment = eventarg.attachmentDetails;
        console.log("Event Fired and Attachment Added!");
        getAttachmentContentAsync(attachment.id, options, callback);
    }
}

Office.context.mailbox.item.addHandlerAsync(Office.EventType.AttachmentsChanged, myHandlerFunction, myCallback);

addItemAttachmentAsync(itemId, attachmentName, options, callback)

Adds an Exchange item, such as a message, as an attachment to the message or appointment.

The addItemAttachmentAsync method attaches the item with the specified Exchange identifier to the item in the compose form. If you specify a callback method, the method is called with one parameter, asyncResult, which contains either the attachment identifier or a code that indicates any error that occurred while attaching the item. You can use the options parameter to pass state information to the callback method, if needed.

You can subsequently use the identifier with the removeAttachmentAsync method to remove the attachment in the same session.

If your Office add-in is running in Outlook on the web, the addItemAttachmentAsync method can attach items to items other than the item that you are editing; however, this is not supported and is not recommended.

[ API set: Mailbox 1.1 ]

addItemAttachmentAsync(itemId: any, attachmentName: string, options?: Office.AsyncContextOptions, callback?: (asyncResult: Office.AsyncResult<string>) => void): void;

Parameters

itemId
any

The Exchange identifier of the item to attach. The maximum length is 100 characters.

attachmentName
string

The name of the attachment that is shown while the attachment is uploading. The maximum length is 255 characters.

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
(asyncResult: Office.AsyncResult<string>) => void

Optional. When the method completes, the function passed in the callback parameter is called with a single parameter of type Office.AsyncResult. On success, the attachment identifier will be provided in the asyncResult.value property. If adding the attachment fails, the asyncResult object will contain an Error object that provides a description of the error.

Returns

void

Remarks

Minimum permission level: ReadWriteItem

Applicable Outlook mode: Message Compose

Errors:

  • NumberOfAttachmentsExceeded: The message or appointment has too many attachments.

Examples

// The following example adds an existing Outlook item as an attachment
// with the name `My Attachment`.
function callback(result) {
    if (result.error) {
        console.log(result.error);
    } else {
        console.log("Attachment added");
    }
}

function addAttachment() {
    // EWS ID of item to attach (shortened for readability).
    var itemId = "AAMkADI1...AAA=";

    // The values in asyncContext can be accessed in the callback.
    var options = { 'asyncContext': { var1: 1, var2: 2 } };

    Office.context.mailbox.item.addItemAttachmentAsync(itemId, "My Attachment", options, callback);
}

addItemAttachmentAsync(itemId, attachmentName, callback)

Adds an Exchange item, such as a message, as an attachment to the message or appointment.

The addItemAttachmentAsync method attaches the item with the specified Exchange identifier to the item in the compose form. If you specify a callback method, the method is called with one parameter, asyncResult, which contains either the attachment identifier or a code that indicates any error that occurred while attaching the item. You can use the options parameter to pass state information to the callback method, if needed.

You can subsequently use the identifier with the removeAttachmentAsync method to remove the attachment in the same session.

If your Office add-in is running in Outlook on the web, the addItemAttachmentAsync method can attach items to items other than the item that you are editing; however, this is not supported and is not recommended.

[ API set: Mailbox 1.1 ]

addItemAttachmentAsync(itemId: any, attachmentName: string, callback?: (asyncResult: Office.AsyncResult<string>) => void): void;

Parameters

itemId
any

The Exchange identifier of the item to attach. The maximum length is 100 characters.

attachmentName
string

The name of the attachment that is shown while the attachment is uploading. The maximum length is 255 characters.

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

Optional. When the method completes, the function passed in the callback parameter is called with a single parameter of type Office.AsyncResult. On success, the attachment identifier will be provided in the asyncResult.value property. If adding the attachment fails, the asyncResult object will contain an Error object that provides a description of the error.

Returns

void

Remarks

Minimum permission level: ReadWriteItem

Applicable Outlook mode: Message Compose

Errors:

  • NumberOfAttachmentsExceeded: The message or appointment has too many attachments.

close()

Closes the current item that is being composed

The behaviors of the close method depends on the current state of the item being composed. If the item has unsaved changes, the client prompts the user to save, discard, or close the action.

In the Outlook desktop client, if the message is an inline reply, the close method has no effect.

Note: In Outlook on the web, if the item is an appointment and it has previously been saved using saveAsync, the user is prompted to save, discard, or cancel even if no changes have occurred since the item was last saved.

[ API set: Mailbox 1.3 ]

close(): void;

Returns

void

Remarks

Minimum permission level: Restricted

Applicable Outlook mode: Message Compose

getAttachmentContentAsync(attachmentId, options, callback)

Gets an attachment from a message or appointment and returns it as an AttachmentContent object.

The getAttachmentContentAsync method gets the attachment with the specified identifier from the item. As a best practice, you should use the identifier to retrieve an attachment in the same session that the attachmentIds were retrieved with the getAttachmentsAsync or item.attachments call. In Outlook on the web and mobile devices, the attachment identifier is valid only within the same session. A session is over when the user closes the app, or if the user starts composing an inline form then subsequently pops out the form to continue in a separate window.

[ API set: Mailbox 1.8 ]

getAttachmentContentAsync(attachmentId: string, options?: Office.AsyncContextOptions, callback?: (asyncResult: Office.AsyncResult<AttachmentContent>) => void): void;

Parameters

attachmentId
string

The identifier of the attachment you want to get.

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
(asyncResult: Office.AsyncResult<AttachmentContent>) => void

Optional. When the method completes, the function passed in the callback parameter is called with a single parameter, asyncResult, which is an Office.AsyncResult object. If the call fails, the asyncResult.error property will contain and error code with the reason for the failure.

Returns

void

Remarks

Minimum permission level: ReadItem

Applicable Outlook mode: Message Compose

Errors:

  • InvalidAttachmentId: The attachment identifier does not exist.

Examples

var item = Office.context.mailbox.item;
var options = {asyncContext: {currentItem: item}};
item.getAttachmentsAsync(options, callback);

function callback(result) {
    if (result.value.length > 0) {
        for (i = 0 ; i < result.value.length ; i++) {
            result.asyncContext.currentItem.getAttachmentContentAsync(result.value[i].id, handleAttachmentsCallback);
        }
    }
}

function handleAttachmentsCallback(result) {
    // Parse string to be a url, an .eml file, a base64-encoded string, or an .icalendar file.
    switch (result.value.format) {
        case Office.MailboxEnums.AttachmentContentFormat.Base64:
            // Handle file attachment.
            break;
        case Office.MailboxEnums.AttachmentContentFormat.Eml:
            // Handle email item attachment.
            break;
        case Office.MailboxEnums.AttachmentContentFormat.ICalendar:
            // Handle .icalender attachment.
            break;
        case Office.MailboxEnums.AttachmentContentFormat.Url:
            // Handle cloud attachment.
            break;
        default:
            // Handle attachment formats that are not supported.
    }
}

getAttachmentContentAsync(attachmentId, callback)

Gets an attachment from a message or appointment and returns it as an AttachmentContent object.

The getAttachmentContentAsync method gets the attachment with the specified identifier from the item. As a best practice, you should use the identifier to retrieve an attachment in the same session that the attachmentIds were retrieved with the getAttachmentsAsync or item.attachments call. In Outlook on the web and mobile devices, the attachment identifier is valid only within the same session. A session is over when the user closes the app, or if the user starts composing an inline form then subsequently pops out the form to continue in a separate window.

[ API set: Mailbox 1.8 ]

getAttachmentContentAsync(attachmentId: string, callback?: (asyncResult: Office.AsyncResult<AttachmentContent>) => void): void;

Parameters

attachmentId
string

The identifier of the attachment you want to get.

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

Optional. When the method completes, the function passed in the callback parameter is called with a single parameter, asyncResult, which is an Office.AsyncResult object. If the call fails, the asyncResult.error property will contain and error code with the reason for the failure.

Returns

void

Remarks

Minimum permission level: ReadItem

Applicable Outlook mode: Message Compose

Errors:

  • InvalidAttachmentId: The attachment identifier does not exist.

getAttachmentsAsync(options, callback)

Gets the item's attachments as an array.

[ API set: Mailbox 1.8 ]

getAttachmentsAsync(options?: Office.AsyncContextOptions, callback?: (asyncResult: Office.AsyncResult<AttachmentDetails[]>) => 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
(asyncResult: Office.AsyncResult<AttachmentDetails>) => void[]

Optional. When the method completes, the function passed in the callback parameter is called with a single parameter of type Office.AsyncResult. If the call fails, the asyncResult.error property will contain and error code with the reason for the failure.

Returns

void

Remarks

Minimum permission level: ReadItem

Applicable Outlook mode: Message Compose

getAttachmentsAsync(callback)

Gets the item's attachments as an array.

[ API set: Mailbox 1.8 ]

getAttachmentsAsync(callback?: (asyncResult: Office.AsyncResult<AttachmentDetails[]>) => void): void;

Parameters

callback
(asyncResult: Office.AsyncResult<AttachmentDetails>) => void[]

Optional. When the method completes, the function passed in the callback parameter is called with a single parameter of type Office.AsyncResult. If the call fails, the asyncResult.error property will contain and error code with the reason for the failure.

Returns

void

Remarks

Minimum permission level: ReadItem

Applicable Outlook mode: Message Compose

Examples

var item = Office.context.mailbox.item;
var outputString = "";
item.getAttachmentsAsync(callback);

function callback(result) {
    if (result.value.length > 0) {
        for (i = 0 ; i < result.value.length ; i++) {
            var attachment = result.value [i];
            outputString += "<BR>" + i + ". Name: ";
            outputString += attachment.name;
            outputString += "<BR>ID: " + attachment.id;
            outputString += "<BR>contentType: " + attachment.contentType;
            outputString += "<BR>size: " + attachment.size;
            outputString += "<BR>attachmentType: " + attachment.attachmentType;
            outputString += "<BR>isInline: " + attachment.isInline;
        }
    }
}

getItemIdAsync(options, callback)

Asynchronously gets the ID of a saved item.

When invoked, this method returns the item ID via the callback method.

Note: If your add-in calls getItemIdAsync on an item in compose mode (e.g., to get an itemId to use with EWS or the REST API), be aware that when Outlook is in cached mode, it may take some time before the item is synced to the server. Until the item is synced, the itemId is not recognized and using it returns an error.

[ API set: Mailbox 1.8 ]

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

Parameters

options
Office.AsyncContextOptions

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
(asyncResult: Office.AsyncResult<string>) => void

When the method completes, the function passed in the callback parameter is called with a single parameter of type Office.AsyncResult.

Returns

void

Remarks

Minimum permission level: ReadItem

Applicable Outlook mode: Message Compose

Errors:

  • ItemNotSaved: The id can't be retrieved until the item is saved.

getItemIdAsync(callback)

Asynchronously gets the ID of a saved item.

When invoked, this method returns the item ID via the callback method.

Note: If your add-in calls getItemIdAsync on an item in compose mode (e.g., to get an itemId to use with EWS or the REST API), be aware that when Outlook is in cached mode, it may take some time before the item is synced to the server. Until the item is synced, the itemId is not recognized and using it returns an error.

[ API set: Mailbox 1.8 ]

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

Parameters

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

When the method completes, the function passed in the callback parameter is called with a single parameter of type Office.AsyncResult.

Returns

void

Remarks

Minimum permission level: ReadItem

Applicable Outlook mode: Message Compose

Errors:

  • ItemNotSaved: The id can't be retrieved until the item is saved.

getSelectedDataAsync(coercionType, options, callback)

Asynchronously returns selected data from the subject or body of a message.

If there is no selection but the cursor is in the body or subject, the method returns an empty string for the selected data. If a field other than the body or subject is selected, the method returns the InvalidSelection error.

To access the selected data from the callback method, call asyncResult.value.data. To access the source property that the selection comes from, call asyncResult.value.sourceProperty, which will be either body or subject.

[ API set: Mailbox 1.2 ]

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

Parameters

coercionType
Office.CoercionType | string

Requests a format for the data. If Text, the method returns the plain text as a string, removing any HTML tags present. If HTML, the method returns the selected text, whether it is plaintext or HTML.

options
Office.AsyncContextOptions

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
(asyncResult: Office.AsyncResult<any>) => void

When the method completes, the function passed in the callback parameter is called with a single parameter of type Office.AsyncResult.

Returns

void

The selected data as a string with format determined by coercionType.

Remarks

Minimum permission level: ReadItem

Applicable Outlook mode: Message Compose

Examples

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

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

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

getSelectedDataAsync(coercionType, callback)

Asynchronously returns selected data from the subject or body of a message.

If there is no selection but the cursor is in the body or subject, the method returns an empty string for the selected data. If a field other than the body or subject is selected, the method returns the InvalidSelection error.

To access the selected data from the callback method, call asyncResult.value.data. To access the source property that the selection comes from, call asyncResult.value.sourceProperty, which will be either body or subject.

[ API set: Mailbox 1.2 ]

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

Parameters

coercionType
Office.CoercionType | string

Requests a format for the data. If Text, the method returns the plain text as a string, removing any HTML tags present. If HTML, the method returns the selected text, whether it is plaintext or HTML.

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

When the method completes, the function passed in the callback parameter is called with a single parameter of type Office.AsyncResult.

Returns

void

The selected data as a string with format determined by coercionType.

Remarks

Minimum permission level: ReadItem

Applicable Outlook mode: Message Compose

getSharedPropertiesAsync(options, callback)

Gets the properties of an appointment or message in a shared folder, calendar, or mailbox.

Note: This method is not supported in Outlook on Mac, iOS, or Android.

[ API set: Mailbox 1.8 ]

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

Parameters

options
Office.AsyncContextOptions

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
(asyncResult: Office.AsyncResult<SharedProperties>) => void

When the method completes, the function passed in the callback parameter is called with a single parameter of type Office.AsyncResult. The value property of the result is the properties of the shared item.

Returns

void

Remarks

Minimum permission level: ReadItem

Applicable Outlook mode: Message Compose

getSharedPropertiesAsync(callback)

Gets the properties of an appointment or message in a shared folder, calendar, or mailbox.

Note: This method is not supported in Outlook on Mac, iOS, or Android.

[ API set: Mailbox 1.8 ]

getSharedPropertiesAsync(callback: (asyncResult: Office.AsyncResult<SharedProperties>) => void): void;

Parameters

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

When the method completes, the function passed in the callback parameter is called with a single parameter of type Office.AsyncResult. The value property of the result is the properties of the shared item.

Returns

void

Remarks

Minimum permission level: ReadItem

Applicable Outlook mode: Message Compose

Examples

Office.context.mailbox.item.getSharedPropertiesAsync(callback);

function callback (asyncResult) {
    var context = asyncResult.context;
    var sharedProperties = asyncResult.value;
}

loadCustomPropertiesAsync(callback, userContext)

Asynchronously loads custom properties for this add-in on the selected item.

Custom properties are stored as key/value pairs on a per-app, per-item basis. This method returns a CustomProperties object in the callback, which provides methods to access the custom properties specific to the current item and the current add-in. Custom properties are not encrypted on the item, so this should not be used as secure storage.

The custom properties are provided as a CustomProperties object in the asyncResult.value property. This object can be used to get, set, and remove custom properties from the item and save changes to the custom property set back to the server.

loadCustomPropertiesAsync(callback: (asyncResult: Office.AsyncResult<CustomProperties>) => void, userContext?: any): void;

Parameters

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

When the method completes, the function passed in the callback parameter is called with a single parameter of type Office.AsyncResult.

userContext
any

Optional. Developers can provide any object they wish to access in the callback function. This object can be accessed by the asyncResult.asyncContext property in the callback function.

Returns

void

Remarks

Minimum permission level: ReadItem

Applicable Outlook mode: Message Compose

Examples

// The following example shows how to use the loadCustomPropertiesAsync method
// to asynchronously load custom properties that are specific to the current item.
// The example also shows how to use the saveAsync method to save these properties
// back to the server. After loading the custom properties, the example uses the
// get method to read the custom property myProp, the set method to write the
// custom property otherProp, and then finally calls the saveAsync method to save
// the custom properties.
Office.initialize = function () {
    // Checks for the DOM to load using the jQuery ready function.
    $(document).ready(function () {
        // After the DOM is loaded, add-in-specific code can run.
        var mailbox = Office.context.mailbox;
        mailbox.item.loadCustomPropertiesAsync(customPropsCallback);
    });
};

function customPropsCallback(asyncResult) {
    var customProps = asyncResult.value;
    var myProp = customProps.get("myProp");

    customProps.set("otherProp", "value");
    customProps.saveAsync(saveCallback);
}

function saveCallback(asyncResult) {
}

removeAttachmentAsync(attachmentId, options, callback)

Removes an attachment from a message or appointment.

The removeAttachmentAsync method removes the attachment with the specified identifier from the item. As a best practice, you should use the attachment identifier to remove an attachment only if the same mail app has added that attachment in the same session. In Outlook on the web and mobile devices, the attachment identifier is valid only within the same session. A session is over when the user closes the app, or if the user starts composing an inline form then subsequently pops out the form to continue in a separate window.

[ API set: Mailbox 1.1 ]

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

Parameters

attachmentId
string

The identifier of the attachment to remove.

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
(asyncResult: 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. If removing the attachment fails, the asyncResult.error property will contain an error code with the reason for the failure.

Returns

void

Remarks

Minimum permission level: ReadWriteItem

Applicable Outlook mode: Message Compose

Errors:

  • InvalidAttachmentId: The attachment identifier does not exist.

Examples

// The following code removes an attachment with an identifier of '0'.
Office.context.mailbox.item.removeAttachmentAsync(
    '0',
    { asyncContext : null },
    function (asyncResult)
    {
        console.log(asyncResult.status);
    }
);

removeAttachmentAsync(attachmentId, callback)

Removes an attachment from a message or appointment.

The removeAttachmentAsync method removes the attachment with the specified identifier from the item. As a best practice, you should use the attachment identifier to remove an attachment only if the same mail app has added that attachment in the same session. In Outlook on the web and mobile devices, the attachment identifier is valid only within the same session. A session is over when the user closes the app, or if the user starts composing an inline form then subsequently pops out the form to continue in a separate window.

[ API set: Mailbox 1.1 ]

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

Parameters

attachmentId
string

The identifier of the attachment to remove.

callback
(asyncResult: 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. If removing the attachment fails, the asyncResult.error property will contain an error code with the reason for the failure.

Returns

void

Remarks

Minimum permission level: ReadWriteItem

Applicable Outlook mode: Message Compose

Errors:

  • InvalidAttachmentId: The attachment identifier does not exist.

removeHandlerAsync(eventType, options, callback)

Removes the event handlers for a supported event type. Note: Events are available only with task pane.

To see which event types are supported, see Office.EventType for details.

[ API set: Mailbox 1.7 ]

removeHandlerAsync(eventType: Office.EventType | string, options?: Office.AsyncContextOptions, callback?: (asyncResult: Office.AsyncResult<void>) => void): void;

Parameters

eventType
Office.EventType | string

The event that should revoke the handler.

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
(asyncResult: Office.AsyncResult<void>) => void

Optional. When the method completes, the function passed in the callback parameter is called with a single parameter, asyncResult, which is an Office.AsyncResult object.

Returns

void

Remarks

Minimum permission level: ReadItem

Applicable Outlook mode: Message Compose

removeHandlerAsync(eventType, callback)

Removes the event handlers for a supported event type. Note: Events are available only with task pane.

To see which event types are supported, see Office.EventType for details.

[ API set: Mailbox 1.7 ]

removeHandlerAsync(eventType: Office.EventType | string, callback?: (asyncResult: Office.AsyncResult<void>) => void): void;

Parameters

eventType
Office.EventType | string

The event that should revoke the handler.

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

Optional. When the method completes, the function passed in the callback parameter is called with a single parameter, asyncResult, which is an Office.AsyncResult object.

Returns

void

Remarks

Minimum permission level: ReadItem

Applicable Outlook mode: Message Compose

saveAsync(options, callback)

Asynchronously saves an item.

When invoked, this method saves the current message as a draft and returns the item id via the callback method. In Outlook on the web or Outlook in online mode, the item is saved to the server. In Outlook in cached mode, the item is saved to the local cache.

Since appointments have no draft state, if saveAsync is called on an appointment in compose mode, the item will be saved as a normal appointment on the user's calendar. For new appointments that have not been saved before, no invitation will be sent. Saving an existing appointment will send an update to added or removed attendees.

Note: If your add-in calls saveAsync on an item in compose mode in order to get an itemId to use with EWS or the REST API, be aware that when Outlook is in cached mode, it may take some time before the item is actually synced to the server. Until the item is synced, using the itemId will return an error.

Note: The following clients have different behavior for saveAsync on appointments in compose mode:

[ API set: Mailbox 1.3 ]

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

Parameters

options
Office.AsyncContextOptions

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
(asyncResult: Office.AsyncResult<string>) => void

When the method completes, the function passed in the callback parameter is called with a single parameter of type Office.AsyncResult.

Returns

void

Remarks

Minimum permission level: ReadWriteItem

Applicable Outlook mode: Message Compose

Errors:

  • InvalidAttachmentId: The attachment identifier does not exist.

saveAsync(callback)

Asynchronously saves an item.

When invoked, this method saves the current message as a draft and returns the item id via the callback method. In Outlook on the web or Outlook in online mode, the item is saved to the server. In Outlook in cached mode, the item is saved to the local cache.

Since appointments have no draft state, if saveAsync is called on an appointment in compose mode, the item will be saved as a normal appointment on the user's calendar. For new appointments that have not been saved before, no invitation will be sent. Saving an existing appointment will send an update to added or removed attendees.

Note: If your add-in calls saveAsync on an item in compose mode in order to get an itemId to use with EWS or the REST API, be aware that when Outlook is in cached mode, it may take some time before the item is actually synced to the server. Until the item is synced, using the itemId will return an error.

Note: The following clients have different behavior for saveAsync on appointments in compose mode:

[ API set: Mailbox 1.3 ]

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

Parameters

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

When the method completes, the function passed in the callback parameter is called with a single parameter of type Office.AsyncResult.

Returns

void

Remarks

Minimum permission level: ReadWriteItem

Applicable Outlook mode: Message Compose

Errors:

  • InvalidAttachmentId: The attachment identifier does not exist.

Examples

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)

Asynchronously inserts data into the body or subject of a message.

The setSelectedDataAsync method inserts the specified string at the cursor location in the subject or body of the item, or, if text is selected in the editor, it replaces the selected text. If the cursor is not in the body or subject field, an error is returned. After insertion, the cursor is placed at the end of the inserted content.

[ API set: Mailbox 1.2 ]

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

Parameters

data
string

The data to be inserted. Data is not to exceed 1,000,000 characters. If more than 1,000,000 characters are passed in, an ArgumentOutOfRange exception is thrown.

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: If text, the current style is applied in Outlook on the web and desktop clients. If the field is an HTML editor, only the text data is inserted, even if the data is HTML. If html and the field supports HTML (the subject doesn't), the current style is applied in Outlook on the web and the default style is applied in Outlook on desktop clients. If the field is a text field, an InvalidDataFormat error is returned. If coercionType is not set, the result depends on the field: if the field is HTML then HTML is used; if the field is text, then plain text is used.

callback
(asyncResult: 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.

Returns

void

Remarks

Minimum permission level: ReadWriteItem

Applicable Outlook mode: Message Compose

Errors:

  • InvalidAttachmentId: The attachment identifier does not exist.

Examples

Office.context.mailbox.item.setSelectedDataAsync("<b>Hello World!</b>", { coercionType : "html" });

setSelectedDataAsync(data, callback)

Asynchronously inserts data into the body or subject of a message.

The setSelectedDataAsync method inserts the specified string at the cursor location in the subject or body of the item, or, if text is selected in the editor, it replaces the selected text. If the cursor is not in the body or subject field, an error is returned. After insertion, the cursor is placed at the end of the inserted content.

[ API set: Mailbox 1.2 ]

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

Parameters

data
string

The data to be inserted. Data is not to exceed 1,000,000 characters. If more than 1,000,000 characters are passed in, an ArgumentOutOfRange exception is thrown.

callback
(asyncResult: 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.

Returns

void

Remarks

Minimum permission level: ReadWriteItem

Applicable Outlook mode: Message Compose

Errors:

  • InvalidAttachmentId: The attachment identifier does not exist.

Examples

Office.context.mailbox.item.setSelectedDataAsync("Hello World!");