Office.Mailbox interface

Provides access to the Outlook Add-in object model for Microsoft Outlook and Microsoft Outlook on the web.

Namespaces:

  • diagnostics: Provides diagnostic information to an Outlook add-in.

  • item: Provides methods and properties for accessing a message or appointment in an Outlook add-in.

  • userProfile: Provides information about the user in an Outlook add-in.

[ API set: Mailbox 1.0 ]

Remarks

Minimum permission level: Restricted

Applicable Outlook mode: Compose or Read

Properties

diagnostics

Provides diagnostic information to an Outlook add-in.

Contains the following members:

  • hostName (string): A string that represents the name of the host application. It should be one of the following values: "Outlook", "OutlookWebApp", "OutlookIOS", or "OutlookAndroid". Note: The "Outlook" value is returned for Outlook on desktop clients (i.e., Windows and Mac).

  • hostVersion (string): A string that represents the version of either the host application or the Exchange Server (e.g., "15.0.468.0"). If the mail add-in is running in Outlook on desktop or mobile clients, the hostVersion property returns the version of the host application, Outlook. In Outlook on the web, the property returns the version of the Exchange Server.

  • OWAView (MailboxEnums.OWAView or string): An enum (or string literal) that represents the current view of Outlook on the web. If the host application is not Outlook on the web, then accessing this property results in undefined. Outlook on the web has three views ("OneColumn" - displayed when the screen is narrow, "TwoColumns" - displayed when the screen is wider, and "ThreeColumns" - displayed when the screen is wide) that correspond to the width of the screen and the window, and the number of columns that can be displayed.

More information is under Office.Diagnostics.

[ API set: Mailbox 1.0 ]

ewsUrl

Gets the URL of the Exchange Web Services (EWS) endpoint for this email account. Read mode only.

Your app must have the ReadItem permission specified in its manifest to call the ewsUrl member in read mode.

In compose mode you must call the saveAsync method before you can use the ewsUrl member. Your app must have ReadWriteItem permissions to call the saveAsync method.

[ API set: Mailbox 1.0 ]

item

The mailbox item. Depending on the context in which the add-in opened, the item may be of any number of types. If you want to see IntelliSense for only a specific type, you should cast this item to one of the following: ItemCompose, ItemRead, MessageCompose, MessageRead, AppointmentCompose, AppointmentRead

masterCategories

Gets an object that provides methods to manage the categories master list associated with a mailbox.

[ API set: Mailbox Preview ]

restUrl

Gets the URL of the REST endpoint for this email account.

Your app must have the ReadItem permission specified in its manifest to call the restUrl member in read mode.

In compose mode you must call the saveAsync method before you can use the restUrl member. Your app must have ReadWriteItem permissions to call the saveAsync method.

[ API set: Mailbox 1.5 ]

userProfile

Information about the user associated with the mailbox. This includes their account type, display name, email address, and time zone.

More information is under Office.UserProfile

Methods

addHandlerAsync(eventType, handler, options, callback)

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

Currently, the only supported event type is Office.EventType.ItemChanged. In Preview, Office.EventType.OfficeThemeChanged is also supported.

[ API set: Mailbox 1.5 ]

addHandlerAsync(eventType, handler, callback)

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

Currently, the only supported event type is Office.EventType.ItemChanged. In Preview, Office.EventType.OfficeThemeChanged is also supported.

[ API set: Mailbox 1.5 ]

convertToEwsId(itemId, restVersion)

Converts an item ID formatted for REST into EWS format.

Item IDs retrieved via a REST API (such as the Outlook Mail API or the Microsoft Graph) use a different format than the format used by Exchange Web Services (EWS). The convertToEwsId method converts a REST-formatted ID into the proper format for EWS.

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

[ API set: Mailbox 1.3 ]

convertToLocalClientTime(timeValue)

Gets a dictionary containing time information in local client time.

The dates and times used by a mail app for Outlook on the web or desktop clients can use different time zones. Outlook uses the client computer time zone; Outlook on the web uses the time zone set on the Exchange Admin Center (EAC). You should handle date and time values so that the values you display on the user interface are always consistent with the time zone that the user expects.

If the mail app is running in Outlook on desktop clients, the convertToLocalClientTime method will return a dictionary object with the values set to the client computer time zone. If the mail app is running in Outlook on the web, the convertToLocalClientTime method will return a dictionary object with the values set to the time zone specified in the EAC.

[ API set: Mailbox 1.0 ]

convertToRestId(itemId, restVersion)

Converts an item ID formatted for EWS into REST format.

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

[ API set: Mailbox 1.3 ]

convertToUtcClientTime(input)

Gets a Date object from a dictionary containing time information.

The convertToUtcClientTime method converts a dictionary containing a local date and time to a Date object with the correct values for the local date and time.

[ API set: Mailbox 1.0 ]

displayAppointmentForm(itemId)

Displays an existing calendar appointment.

The displayAppointmentForm method opens an existing calendar appointment in a new window on the desktop or in a dialog box on mobile devices.

In Outlook on Mac, you can use this method to display a single appointment that is not part of a recurring series, or the master appointment of a recurring series, but you cannot display an instance of the series. This is because in Outlook on Mac, you cannot access the properties (including the item ID) of instances of a recurring series.

In Outlook on the web, this method opens the specified form only if the body of the form is less than or equal to 32KB number of characters.

If the specified item identifier does not identify an existing appointment, a blank pane opens on the client computer or device, and no error message will be returned.

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

[ API set: Mailbox 1.0 ]

displayMessageForm(itemId)

Displays an existing message.

The displayMessageForm method opens an existing message in a new window on the desktop or in a dialog box on mobile devices.

In Outlook on the web, this method opens the specified form only if the body of the form is less than or equal to 32 KB number of characters.

If the specified item identifier does not identify an existing message, no message will be displayed on the client computer, and no error message will be returned.

Do not use the displayMessageForm with an itemId that represents an appointment. Use the displayAppointmentForm method to display an existing appointment, and displayNewAppointmentForm to display a form to create a new appointment.

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

[ API set: Mailbox 1.0 ]

displayNewAppointmentForm(parameters)

Displays a form for creating a new calendar appointment.

The displayNewAppointmentForm method opens a form that enables the user to create a new appointment or meeting. If parameters are specified, the appointment form fields are automatically populated with the contents of the parameters.

In Outlook on the web, this method always displays a form with an attendees field. If you do not specify any attendees as input arguments, the method displays a form with a Save button. If you have specified attendees, the form would include the attendees and a Send button.

In the Outlook rich client and Outlook RT, if you specify any attendees or resources in the requiredAttendees, optionalAttendees, or resources parameter, this method displays a meeting form with a Send button. If you don't specify any recipients, this method displays an appointment form with a Save & Close button.

If any of the parameters exceed the specified size limits, or if an unknown parameter name is specified, an exception is thrown.

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

[ API set: Mailbox 1.0 ]

displayNewMessageForm(parameters)

Displays a form for creating a new message.

The displayNewMessageForm method opens a form that enables the user to create a new message. If parameters are specified, the message form fields are automatically populated with the contents of the parameters.

If any of the parameters exceed the specified size limits, or if an unknown parameter name is specified, an exception is thrown.

[ API set: Mailbox 1.6 ]

getCallbackTokenAsync(options, callback)

Gets a string that contains a token used to call REST APIs or Exchange Web Services.

The getCallbackTokenAsync method makes an asynchronous call to get an opaque token from the Exchange Server that hosts the user's mailbox. The lifetime of the callback token is 5 minutes.

The token is returned as a string in the asyncResult.value property.

REST Tokens

When a REST token is requested (options.isRest = true), the resulting token will not work to authenticate Exchange Web Services calls. The token will be limited in scope to read-only access to the current item and its attachments, unless the add-in has specified the ReadWriteMailbox permission in its manifest. If the ReadWriteMailbox permission is specified, the resulting token will grant read/write access to mail, calendar, and contacts, including the ability to send mail.

The add-in should use the restUrl property to determine the correct URL to use when making REST API calls.

EWS Tokens

When an EWS token is requested (options.isRest = false), the resulting token will not work to authenticate REST API calls. The token will be limited in scope to accessing the current item.

The add-in should use the ewsUrl property to determine the correct URL to use when making EWS calls.

Note: It is recommended that add-ins use the REST APIs instead of Exchange Web Services whenever possible.

[ API set: Mailbox 1.5 ]

getCallbackTokenAsync(callback, userContext)

Gets a string that contains a token used to get an attachment or item from an Exchange Server.

The getCallbackTokenAsync method makes an asynchronous call to get an opaque token from the Exchange Server that hosts the user's mailbox. The lifetime of the callback token is 5 minutes.

The token is returned as a string in the asyncResult.value property.

You can pass the token and an attachment identifier or item identifier to a third-party system. The third-party system uses the token as a bearer authorization token to call the Exchange Web Services (EWS) GetAttachment or GetItem operation to return an attachment or item. For example, you can create a remote service to get attachments from the selected item.

Your app must have the ReadItem permission specified in its manifest to call the getCallbackTokenAsync method in read mode.

In compose mode you must call the saveAsync method to get an item identifier to pass to the getCallbackTokenAsync method. Your app must have ReadWriteItem permissions to call the saveAsync method.

[ API set: Mailbox 1.0 ]

getUserIdentityTokenAsync(callback, userContext)

Gets a token identifying the user and the Office Add-in.

The token is returned as a string in the asyncResult.value property.

[ API set: Mailbox 1.0 ]

makeEwsRequestAsync(data, callback, userContext)

Makes an asynchronous request to an Exchange Web Services (EWS) service on the Exchange server that hosts the user's mailbox.

In these cases, add-ins should use REST APIs to access the user's mailbox instead.

The makeEwsRequestAsync method sends an EWS request on behalf of the add-in to Exchange.

You cannot request Folder Associated Items with the makeEwsRequestAsync method.

The XML request must specify UTF-8 encoding. <?xml version="1.0" encoding="utf-8"?>

Your add-in must have the ReadWriteMailbox permission to use the makeEwsRequestAsync method. For information about using the ReadWriteMailbox permission and the EWS operations that you can call with the makeEwsRequestAsync method, see Specify permissions for mail add-in access to the user's mailbox.

The XML result of the EWS call is provided as a string in the asyncResult.value property. If the result exceeds 1 MB in size, an error message is returned instead.

Note: This method is not supported in the following scenarios:

  • In Outlook on iOS or Android.

  • When the add-in is loaded in a Gmail mailbox.

Note: The server administrator must set OAuthAuthentication to true on the Client Access Server EWS directory to enable the makeEwsRequestAsync method to make EWS requests.

Version differences

When you use the makeEwsRequestAsync method in mail apps running in Outlook versions earlier than version 15.0.4535.1004, you should set the encoding value to ISO-8859-1.

<?xml version="1.0" encoding="iso-8859-1"?>

You do not need to set the encoding value when your mail app is running in Outlook on the web. You can determine whether your mail app is running in Outlook or Outlook on the web by using the mailbox.diagnostics.hostName property. You can determine what version of Outlook is running by using the mailbox.diagnostics.hostVersion property.

[ API set: Mailbox 1.0 ]

removeHandlerAsync(eventType, options, callback)

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

Currently, the only supported event type is Office.EventType.ItemChanged. In Preview, Office.EventType.OfficeThemeChanged is also supported.

[ API set: Mailbox 1.5 ]

removeHandlerAsync(eventType, callback)

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

Currently, the only supported event type is Office.EventType.ItemChanged. In Preview, Office.EventType.OfficeThemeChanged is also supported.

[ API set: Mailbox 1.5 ]

Property Details

diagnostics

Provides diagnostic information to an Outlook add-in.

Contains the following members:

  • hostName (string): A string that represents the name of the host application. It should be one of the following values: "Outlook", "OutlookWebApp", "OutlookIOS", or "OutlookAndroid". Note: The "Outlook" value is returned for Outlook on desktop clients (i.e., Windows and Mac).

  • hostVersion (string): A string that represents the version of either the host application or the Exchange Server (e.g., "15.0.468.0"). If the mail add-in is running in Outlook on desktop or mobile clients, the hostVersion property returns the version of the host application, Outlook. In Outlook on the web, the property returns the version of the Exchange Server.

  • OWAView (MailboxEnums.OWAView or string): An enum (or string literal) that represents the current view of Outlook on the web. If the host application is not Outlook on the web, then accessing this property results in undefined. Outlook on the web has three views ("OneColumn" - displayed when the screen is narrow, "TwoColumns" - displayed when the screen is wider, and "ThreeColumns" - displayed when the screen is wide) that correspond to the width of the screen and the window, and the number of columns that can be displayed.

More information is under Office.Diagnostics.

[ API set: Mailbox 1.0 ]

diagnostics: Diagnostics;

Property Value

Remarks

Minimum permission level: ReadItem

Applicable Outlook mode: Compose or Read

ewsUrl

Gets the URL of the Exchange Web Services (EWS) endpoint for this email account. Read mode only.

Your app must have the ReadItem permission specified in its manifest to call the ewsUrl member in read mode.

In compose mode you must call the saveAsync method before you can use the ewsUrl member. Your app must have ReadWriteItem permissions to call the saveAsync method.

[ API set: Mailbox 1.0 ]

ewsUrl: string;

Property Value

string

Remarks

Minimum permission level: ReadItem

Applicable Outlook mode: Compose or Read

The ewsUrl value can be used by a remote service to make EWS calls to the user's mailbox. For example, you can create a remote service to get attachments from the selected item.

Note: This member is not supported in Outlook on iOS or Android.

item

The mailbox item. Depending on the context in which the add-in opened, the item may be of any number of types. If you want to see IntelliSense for only a specific type, you should cast this item to one of the following: ItemCompose, ItemRead, MessageCompose, MessageRead, AppointmentCompose, AppointmentRead

item: Item & ItemCompose & ItemRead & MessageRead & MessageCompose & AppointmentRead & AppointmentCompose;

Property Value

masterCategories

Note

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Gets an object that provides methods to manage the categories master list associated with a mailbox.

[ API set: Mailbox Preview ]

masterCategories: MasterCategories;

Property Value

Remarks

Minimum permission level: ReadWriteMailbox

Applicable Outlook mode: Compose or Read

Examples

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

restUrl

Gets the URL of the REST endpoint for this email account.

Your app must have the ReadItem permission specified in its manifest to call the restUrl member in read mode.

In compose mode you must call the saveAsync method before you can use the restUrl member. Your app must have ReadWriteItem permissions to call the saveAsync method.

[ API set: Mailbox 1.5 ]

restUrl: string;

Property Value

string

Remarks

Minimum permission level: ReadItem

Applicable Outlook mode: Compose or Read

The restUrl value can be used to make REST API calls to the user's mailbox.

userProfile

Information about the user associated with the mailbox. This includes their account type, display name, email address, and time zone.

More information is under Office.UserProfile

userProfile: UserProfile;

Property Value

Method Details

addHandlerAsync(eventType, handler, options, callback)

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

Currently, the only supported event type is Office.EventType.ItemChanged. In Preview, Office.EventType.OfficeThemeChanged is also supported.

[ API set: Mailbox 1.5 ]

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

Parameters

eventType
Office.EventType | string

The event that should invoke the handler.

handler
(type: Office.EventType) => void

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. Provides an option for preserving context data of any type, unchanged, for use in a callback.

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: ReadItem

Applicable Outlook mode: Compose or Read

addHandlerAsync(eventType, handler, callback)

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

Currently, the only supported event type is Office.EventType.ItemChanged. In Preview, Office.EventType.OfficeThemeChanged is also supported.

[ API set: Mailbox 1.5 ]

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

Parameters

eventType
Office.EventType | string

The event that should invoke the handler.

handler
(type: Office.EventType) => void

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 of type Office.AsyncResult.

Returns

void

Remarks

Minimum permission level: ReadItem

Applicable Outlook mode: Compose or Read

Examples

Office.initialize = function (reason) {
    $(document).ready(function () {
        Office.context.mailbox.addHandlerAsync(Office.EventType.ItemChanged, loadNewItem, function (result) {
        if (result.status === Office.AsyncResultStatus.Failed) {
                // Handle error.
            }
        });
    });
};

function loadNewItem(eventArgs) {
    // Load the properties of the newly selected item.
    loadProps(Office.context.mailbox.item);
}

convertToEwsId(itemId, restVersion)

Converts an item ID formatted for REST into EWS format.

Item IDs retrieved via a REST API (such as the Outlook Mail API or the Microsoft Graph) use a different format than the format used by Exchange Web Services (EWS). The convertToEwsId method converts a REST-formatted ID into the proper format for EWS.

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

[ API set: Mailbox 1.3 ]

convertToEwsId(itemId: string, restVersion: MailboxEnums.RestVersion | string): string;

Parameters

itemId
string

An item ID formatted for the Outlook REST APIs.

restVersion
MailboxEnums.RestVersion | string

A value indicating the version of the Outlook REST API used to retrieve the item ID.

Returns

string

Remarks

Minimum permission level: Restricted

Applicable Outlook mode: Compose or Read

Examples

// Get an item's ID from a REST API.
var restId = 'AAMkAGVlOTZjNTM3LW...';

// Treat restId as coming from the v2.0 version of the Outlook Mail API.
var ewsId = Office.context.mailbox.convertToEwsId(restId, Office.MailboxEnums.RestVersion.v2_0);

convertToLocalClientTime(timeValue)

Gets a dictionary containing time information in local client time.

The dates and times used by a mail app for Outlook on the web or desktop clients can use different time zones. Outlook uses the client computer time zone; Outlook on the web uses the time zone set on the Exchange Admin Center (EAC). You should handle date and time values so that the values you display on the user interface are always consistent with the time zone that the user expects.

If the mail app is running in Outlook on desktop clients, the convertToLocalClientTime method will return a dictionary object with the values set to the client computer time zone. If the mail app is running in Outlook on the web, the convertToLocalClientTime method will return a dictionary object with the values set to the time zone specified in the EAC.

[ API set: Mailbox 1.0 ]

convertToLocalClientTime(timeValue: Date): LocalClientTime;

Parameters

timeValue
Date

A Date object.

Returns

Remarks

Minimum permission level: ReadItem

Applicable Outlook mode: Compose or Read

convertToRestId(itemId, restVersion)

Converts an item ID formatted for EWS into REST format.

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

[ API set: Mailbox 1.3 ]

convertToRestId(itemId: string, restVersion: MailboxEnums.RestVersion | string): string;

Parameters

itemId
string

An item ID formatted for Exchange Web Services (EWS)

restVersion
MailboxEnums.RestVersion | string

A value indicating the version of the Outlook REST API that the converted ID will be used with.

Returns

string

Remarks

Minimum permission level: Restricted

Applicable Outlook mode: Compose or Read

Item IDs retrieved via EWS or via the itemId property use a different format than the format used by REST APIs (such as the Outlook Mail API or the Microsoft Graph. The convertToRestId method converts an EWS-formatted ID into the proper format for REST.

Examples

// Get the currently selected item's ID.
var ewsId = Office.context.mailbox.item.itemId;

// Convert to a REST ID for the v2.0 version of the Outlook Mail API.
var restId = Office.context.mailbox.convertToRestId(ewsId, Office.MailboxEnums.RestVersion.v2_0);

convertToUtcClientTime(input)

Gets a Date object from a dictionary containing time information.

The convertToUtcClientTime method converts a dictionary containing a local date and time to a Date object with the correct values for the local date and time.

[ API set: Mailbox 1.0 ]

convertToUtcClientTime(input: LocalClientTime): Date;

Parameters

input
LocalClientTime

The local time value to convert.

Returns

Date

A Date object with the time expressed in UTC.

Remarks

Minimum permission level: ReadItem

Applicable Outlook mode: Compose or Read

Examples

// Represents 3:37 PM PDT on Monday, August 26, 2019.
var input = {
    date: 26,
    hours: 15,
    milliseconds: 2,
    minutes: 37,
    month: 7,
    seconds: 2,
    timezoneOffset: -420,
    year: 2019
};

// result should be a Date object.
var result = Office.context.mailbox.convertToUtcClientTime(input);

// Output should be "2019-08-26T22:37:02.002Z".
console.log(result.toISOString());

displayAppointmentForm(itemId)

Displays an existing calendar appointment.

The displayAppointmentForm method opens an existing calendar appointment in a new window on the desktop or in a dialog box on mobile devices.

In Outlook on Mac, you can use this method to display a single appointment that is not part of a recurring series, or the master appointment of a recurring series, but you cannot display an instance of the series. This is because in Outlook on Mac, you cannot access the properties (including the item ID) of instances of a recurring series.

In Outlook on the web, this method opens the specified form only if the body of the form is less than or equal to 32KB number of characters.

If the specified item identifier does not identify an existing appointment, a blank pane opens on the client computer or device, and no error message will be returned.

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

[ API set: Mailbox 1.0 ]

displayAppointmentForm(itemId: string): void;

Parameters

itemId
string

The Exchange Web Services (EWS) identifier for an existing calendar appointment.

Returns

void

Remarks

Minimum permission level: ReadItem

Applicable Outlook mode: Compose or Read

Examples

Office.context.mailbox.displayAppointmentForm(appointmentId);

displayMessageForm(itemId)

Displays an existing message.

The displayMessageForm method opens an existing message in a new window on the desktop or in a dialog box on mobile devices.

In Outlook on the web, this method opens the specified form only if the body of the form is less than or equal to 32 KB number of characters.

If the specified item identifier does not identify an existing message, no message will be displayed on the client computer, and no error message will be returned.

Do not use the displayMessageForm with an itemId that represents an appointment. Use the displayAppointmentForm method to display an existing appointment, and displayNewAppointmentForm to display a form to create a new appointment.

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

[ API set: Mailbox 1.0 ]

displayMessageForm(itemId: string): void;

Parameters

itemId
string

The Exchange Web Services (EWS) identifier for an existing message.

Returns

void

Remarks

Minimum permission level: ReadItem

Applicable Outlook mode: Compose or Read

Examples

Office.context.mailbox.displayMessageForm(messageId);

displayNewAppointmentForm(parameters)

Displays a form for creating a new calendar appointment.

The displayNewAppointmentForm method opens a form that enables the user to create a new appointment or meeting. If parameters are specified, the appointment form fields are automatically populated with the contents of the parameters.

In Outlook on the web, this method always displays a form with an attendees field. If you do not specify any attendees as input arguments, the method displays a form with a Save button. If you have specified attendees, the form would include the attendees and a Send button.

In the Outlook rich client and Outlook RT, if you specify any attendees or resources in the requiredAttendees, optionalAttendees, or resources parameter, this method displays a meeting form with a Send button. If you don't specify any recipients, this method displays an appointment form with a Save & Close button.

If any of the parameters exceed the specified size limits, or if an unknown parameter name is specified, an exception is thrown.

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

[ API set: Mailbox 1.0 ]

displayNewAppointmentForm(parameters: AppointmentForm): void;

Parameters

parameters
AppointmentForm

An AppointmentForm describing the new appointment. All properties are optional.

Returns

void

Remarks

Minimum permission level: ReadItem

Applicable Outlook mode: Read

Examples

var start = new Date();
var end = new Date();
end.setHours(start.getHours() + 1);

Office.context.mailbox.displayNewAppointmentForm(
{
    requiredAttendees: ['bob@contoso.com'],
    optionalAttendees: ['sam@contoso.com'],
    start: start,
    end: end,
    location: 'Home',
    resources: ['projector@contoso.com'],
    subject: 'meeting',
    body: 'Hello World!'
});

displayNewMessageForm(parameters)

Displays a form for creating a new message.

The displayNewMessageForm method opens a form that enables the user to create a new message. If parameters are specified, the message form fields are automatically populated with the contents of the parameters.

If any of the parameters exceed the specified size limits, or if an unknown parameter name is specified, an exception is thrown.

[ API set: Mailbox 1.6 ]

displayNewMessageForm(parameters: any): void;

Parameters

parameters
any

A dictionary containing all values to be filled in for the user in the new form. All parameters are optional.

toRecipients: An array of strings containing the email addresses or an array containing an Office.EmailAddressDetails object for each of the recipients on the To line. The array is limited to a maximum of 100 entries.

ccRecipients: An array of strings containing the email addresses or an array containing an Office.EmailAddressDetails object for each of the recipients on the Cc line. The array is limited to a maximum of 100 entries.

bccRecipients: An array of strings containing the email addresses or an array containing an Office.EmailAddressDetails object for each of the recipients on the Bcc line. The array is limited to a maximum of 100 entries.

subject: A string containing the subject of the message. The string is limited to a maximum of 255 characters.

htmlBody: The HTML body of the message. The body content is limited to a maximum size of 32 KB.

attachments: An array of JSON objects that are either file or item attachments.

attachments.type: Indicates the type of attachment. Must be file for a file attachment or item for an item attachment.

attachments.name: A string that contains the name of the attachment, up to 255 characters in length.

attachments.url: Only used if type is set to file. The URI of the location for the file.

attachments.isInline: Only used if type is set to file. If true, indicates that the attachment will be shown inline in the message body, and should not be displayed in the attachment list.

attachments.itemId: Only used if type is set to item. The EWS item id of the existing e-mail you want to attach to the new message. This is a string up to 100 characters.

Returns

void

Remarks

Minimum permission level: ReadItem

Applicable Outlook mode: Read

Examples

Office.context.mailbox.displayNewMessageForm(
{
    // Copy the To line from current item.
    toRecipients: Office.context.mailbox.item.to,
    ccRecipients: ['sam@contoso.com'],
    subject: 'Outlook add-ins are cool!',
    htmlBody: 'Hello <b>World</b>!<br/><img src="cid:image.png"></i>',
    attachments: [
    {
        type: 'file',
        name: 'image.png',
        url: 'http://contoso.com/image.png',
        isInline: true
    }
    ]
});

getCallbackTokenAsync(options, callback)

Gets a string that contains a token used to call REST APIs or Exchange Web Services.

The getCallbackTokenAsync method makes an asynchronous call to get an opaque token from the Exchange Server that hosts the user's mailbox. The lifetime of the callback token is 5 minutes.

The token is returned as a string in the asyncResult.value property.

REST Tokens

When a REST token is requested (options.isRest = true), the resulting token will not work to authenticate Exchange Web Services calls. The token will be limited in scope to read-only access to the current item and its attachments, unless the add-in has specified the ReadWriteMailbox permission in its manifest. If the ReadWriteMailbox permission is specified, the resulting token will grant read/write access to mail, calendar, and contacts, including the ability to send mail.

The add-in should use the restUrl property to determine the correct URL to use when making REST API calls.

EWS Tokens

When an EWS token is requested (options.isRest = false), the resulting token will not work to authenticate REST API calls. The token will be limited in scope to accessing the current item.

The add-in should use the ewsUrl property to determine the correct URL to use when making EWS calls.

Note: It is recommended that add-ins use the REST APIs instead of Exchange Web Services whenever possible.

[ API set: Mailbox 1.5 ]

getCallbackTokenAsync(options: Office.AsyncContextOptions & { isRest?: boolean }, callback: (asyncResult: Office.AsyncResult<string>) => void): void;

Parameters

options
Office.AsyncContextOptions & { isRest?: boolean }

An object literal that contains one or more of the following properties. isRest: Determines if the token provided will be used for the Outlook REST APIs or Exchange Web Services. Default value is false. asyncContext: Any state data that is passed to the asynchronous 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. The token is returned as a string in the asyncResult.value property. If there was an error, the asyncResult.error and asyncResult.diagnostics properties may provide additional information.

Returns

void

Remarks

Minimum permission level: ReadItem

Applicable Outlook mode: Compose or Read

Errors:

  • HTTPRequestFailure: The request has failed. Please look at the diagnostics object for the HTTP error code.

  • InternalServerError: The Exchange server returned an error. Please look at the diagnostics object for more information.

  • NetworkError: The user is no longer connected to the network. Please check your network connection and try again.

Examples

function getCallbackToken() {
    var options = {
        isRest: true,
        asyncContext: { message: 'Hello World!' }
    };

    Office.context.mailbox.getCallbackTokenAsync(options, cb);
}

function cb(asyncResult) {
    var token = asyncResult.value;
}

getCallbackTokenAsync(callback, userContext)

Gets a string that contains a token used to get an attachment or item from an Exchange Server.

The getCallbackTokenAsync method makes an asynchronous call to get an opaque token from the Exchange Server that hosts the user's mailbox. The lifetime of the callback token is 5 minutes.

The token is returned as a string in the asyncResult.value property.

You can pass the token and an attachment identifier or item identifier to a third-party system. The third-party system uses the token as a bearer authorization token to call the Exchange Web Services (EWS) GetAttachment or GetItem operation to return an attachment or item. For example, you can create a remote service to get attachments from the selected item.

Your app must have the ReadItem permission specified in its manifest to call the getCallbackTokenAsync method in read mode.

In compose mode you must call the saveAsync method to get an item identifier to pass to the getCallbackTokenAsync method. Your app must have ReadWriteItem permissions to call the saveAsync method.

[ API set: Mailbox 1.0 ]

getCallbackTokenAsync(callback: (asyncResult: Office.AsyncResult<string>) => void, userContext?: any): 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. The token is returned as a string in the asyncResult.value property. If there was an error, the asyncResult.error and asyncResult.diagnostics properties may provide additional information.

userContext
any

Optional. Any state data that is passed to the asynchronous method.

Returns

void

Remarks

Minimum permission level: ReadItem

Applicable Outlook mode: Compose or Read

Errors:

  • HTTPRequestFailure: The request has failed. Please look at the diagnostics object for the HTTP error code.

  • InternalServerError: The Exchange server returned an error. Please look at the diagnostics object for more information.

  • NetworkError: The user is no longer connected to the network. Please check your network connection and try again.

Examples

function getCallbackToken() {
    Office.context.mailbox.getCallbackTokenAsync(cb);
}

function cb(asyncResult) {
    var token = asyncResult.value;
}

getUserIdentityTokenAsync(callback, userContext)

Gets a token identifying the user and the Office Add-in.

The token is returned as a string in the asyncResult.value property.

[ API set: Mailbox 1.0 ]

getUserIdentityTokenAsync(callback: (asyncResult: Office.AsyncResult<string>) => void, userContext?: any): 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. The token is returned as a string in the asyncResult.value property. If there was an error, the asyncResult.error and asyncResult.diagnostics properties may provide additional information.

userContext
any

Optional. Any state data that is passed to the asynchronous method.

Returns

void

Remarks

Minimum permission level: ReadItem

Applicable Outlook mode: Compose or Read

The getUserIdentityTokenAsync method returns a token that you can use to identify and authenticate the add-in and user with a third-party system.

Errors:

  • HTTPRequestFailure: The request has failed. Please look at the diagnostics object for the HTTP error code.

  • InternalServerError: The Exchange server returned an error. Please look at the diagnostics object for more information.

  • NetworkError: The user is no longer connected to the network. Please check your network connection and try again.

Examples

function getIdentityToken() {
    Office.context.mailbox.getUserIdentityTokenAsync(cb);
}

function cb(asyncResult) {
    var token = asyncResult.value;
}

makeEwsRequestAsync(data, callback, userContext)

Makes an asynchronous request to an Exchange Web Services (EWS) service on the Exchange server that hosts the user's mailbox.

In these cases, add-ins should use REST APIs to access the user's mailbox instead.

The makeEwsRequestAsync method sends an EWS request on behalf of the add-in to Exchange.

You cannot request Folder Associated Items with the makeEwsRequestAsync method.

The XML request must specify UTF-8 encoding. <?xml version="1.0" encoding="utf-8"?>

Your add-in must have the ReadWriteMailbox permission to use the makeEwsRequestAsync method. For information about using the ReadWriteMailbox permission and the EWS operations that you can call with the makeEwsRequestAsync method, see Specify permissions for mail add-in access to the user's mailbox.

The XML result of the EWS call is provided as a string in the asyncResult.value property. If the result exceeds 1 MB in size, an error message is returned instead.

Note: This method is not supported in the following scenarios:

  • In Outlook on iOS or Android.

  • When the add-in is loaded in a Gmail mailbox.

Note: The server administrator must set OAuthAuthentication to true on the Client Access Server EWS directory to enable the makeEwsRequestAsync method to make EWS requests.

Version differences

When you use the makeEwsRequestAsync method in mail apps running in Outlook versions earlier than version 15.0.4535.1004, you should set the encoding value to ISO-8859-1.

<?xml version="1.0" encoding="iso-8859-1"?>

You do not need to set the encoding value when your mail app is running in Outlook on the web. You can determine whether your mail app is running in Outlook or Outlook on the web by using the mailbox.diagnostics.hostName property. You can determine what version of Outlook is running by using the mailbox.diagnostics.hostVersion property.

[ API set: Mailbox 1.0 ]

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

Parameters

data
any

The EWS request.

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. The value property of the result is the XML of the EWS request provided as a string. If the result exceeds 1 MB in size, an error message is returned instead.

userContext
any

Optional. Any state data that is passed to the asynchronous method.

Returns

void

Remarks

Minimum permission level: ReadWriteMailbox

Applicable Outlook mode: Compose or Read

Examples

function getSubjectRequest(id) {
    // Return a GetItem operation request for the subject of the specified item.
    var request =
        '<?xml version="1.0" encoding="utf-8"?>' +
        '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' +
        '               xmlns:xsd="http://www.w3.org/2001/XMLSchema"' +
        '               xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"' +
        '               xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">' +
        '  <soap:Header>' +
        '    <RequestServerVersion Version="Exchange2013" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" soap:mustUnderstand="0" />' +
        '  </soap:Header>' +
        '  <soap:Body>' +
        '    <GetItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">' +
        '      <ItemShape>' +
        '        <t:BaseShape>IdOnly</t:BaseShape>' +
        '        <t:AdditionalProperties>' +
        '            <t:FieldURI FieldURI="item:Subject"/>' +
        '        </t:AdditionalProperties>' +
        '      </ItemShape>' +
        '      <ItemIds><t:ItemId Id="' + id + '"/></ItemIds>' +
        '    </GetItem>' +
        '  </soap:Body>' +
        '</soap:Envelope>';

    return request;
}

function sendRequest() {
    // Create a local variable that contains the mailbox.
    Office.context.mailbox.makeEwsRequestAsync(
        getSubjectRequest(mailbox.item.itemId), callback);
}

function callback(asyncResult)  {
    var result = asyncResult.value;
    var context = asyncResult.asyncContext;

    // Process the returned response here.
}

removeHandlerAsync(eventType, options, callback)

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

Currently, the only supported event type is Office.EventType.ItemChanged. In Preview, Office.EventType.OfficeThemeChanged is also supported.

[ API set: Mailbox 1.5 ]

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. Provides an option for preserving context data of any type, unchanged, for use in a callback.

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: ReadItem

Applicable Outlook mode: Compose or Read

removeHandlerAsync(eventType, callback)

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

Currently, the only supported event type is Office.EventType.ItemChanged. In Preview, Office.EventType.OfficeThemeChanged is also supported.

[ API set: Mailbox 1.5 ]

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 of type Office.AsyncResult.

Returns

void

Remarks

Minimum permission level: ReadItem

Applicable Outlook mode: Compose or Read