Configure your Outlook add-in for event-based activation
Without the event-based activation feature, a user has to explicitly launch an add-in to complete their tasks. This feature enables your add-in to run tasks based on certain events, particularly for operations that apply to every item. You can also integrate with the task pane and function commands.
By the end of this walkthrough, you'll have an add-in that runs whenever a new item is created and sets the subject.
Note
Support for this feature was introduced in requirement set 1.10, with additional events now available in subsequent requirement sets. For details about an event's minimum requirement set and the clients and platforms that support it, see Supported events and Requirement sets supported by Exchange servers and Outlook clients.
Event-based activation isn't supported in Outlook on iOS or Android.
Important
Event-based activation isn't yet supported for the Teams manifest for Office Add-ins (preview). We are working on providing that support soon.
Supported events
The following table lists events that are currently available and the supported clients for each event. When an event is raised, the handler receives an event object which may include details specific to the type of event. The Description column includes a link to the related object where applicable.
| Event canonical nameand XML manifest name | Teams manifest name | Description | Minimum requirement set and supported clients |
|---|---|---|---|
OnNewMessageCompose |
newMessageComposeCreated | On composing a new message (includes reply, reply all, and forward) but not on editing, for example, a draft. | 1.10 - Windows1 - Web browser - New Mac UI |
OnNewAppointmentOrganizer |
newAppointmentOrganizerCreated | On creating a new appointment but not on editing an existing one. | 1.10 - Windows1 - Web browser - New Mac UI |
OnMessageAttachmentsChanged |
messageAttachmentsChanged | On adding or removing attachments while composing a message. Event-specific data object: AttachmentsChangedEventArgs |
1.11 - Windows1 - Web browser - New Mac UI |
OnAppointmentAttachmentsChanged |
appointmentAttachmentsChanged | On adding or removing attachments while composing an appointment. Event-specific data object: AttachmentsChangedEventArgs |
1.11 - Windows1 - Web browser - New Mac UI |
OnMessageRecipientsChanged |
messageRecipientsChanged | On adding or removing recipients while composing a message. Event-specific data object: RecipientsChangedEventArgs |
1.11 - Windows1 - Web browser - New Mac UI |
OnAppointmentAttendeesChanged |
appointmentAttendeesChanged | On adding or removing attendees while composing an appointment. Event-specific data object: RecipientsChangedEventArgs |
1.11 - Windows1 - Web browser - New Mac UI |
OnAppointmentTimeChanged |
appointmentTimeChanged | On changing date/time while composing an appointment. Event-specific data object: AppointmentTimeChangedEventArgs |
1.11 - Windows1 - Web browser - New Mac UI |
OnAppointmentRecurrenceChanged |
appointmentRecurrenceChanged | On adding, changing, or removing the recurrence details while composing an appointment. If the date/time is changed, the OnAppointmentTimeChanged event will also be fired.Event-specific data object: RecurrenceChangedEventArgs |
1.11 - Windows1 - Web browser - New Mac UI |
OnInfoBarDismissClicked |
infoBarDismissClicked | On dismissing a notification while composing a message or appointment item. Only the add-in that added the notification will be notified. Event-specific data object: InfobarClickedEventArgs |
1.11 - Windows1 - Web browser - New Mac UI |
OnMessageSend |
messageSending | On sending a message item. To learn more, see the Smart Alerts walkthrough. | 1.12 - Windows1 - Web browser - New Mac UI |
OnAppointmentSend |
appointmentSending | On sending an appointment item. To learn more, see the Smart Alerts walkthrough. | 1.12 - Windows1 - Web browser - New Mac UI |
OnMessageCompose |
messageComposeOpened | On composing a new message (includes reply, reply all, and forward) or editing a draft. | 1.12 - Windows1 - Web browser - New Mac UI |
OnAppointmentOrganizer |
appointmentOrganizerOpened | On creating a new appointment or editing an existing one. | 1.12 - Windows1 - Web browser - New Mac UI |
Note
1 Event-based add-ins in Outlook on Windows require a minimum of Windows 10 Version 1903 (Build 18362) or Windows Server 2019 Version 1903 to run.
Set up your environment
Complete the Outlook quick start which creates an add-in project with the Yeoman generator for Office Add-ins.
Configure the manifest
To configure the manifest, select the tab for the type of manifest you are using.
To enable event-based activation of your add-in, you must configure the Runtimes element and LaunchEvent extension point in the VersionOverridesV1_1 node of the manifest. For now, DesktopFormFactor is the only supported form factor.
In your code editor, open the quick start project.
Open the manifest.xml file located at the root of your project.
Select the entire <VersionOverrides> node (including open and close tags) and replace it with the following XML, then save your changes.
<VersionOverrides xmlns="http://schemas.microsoft.com/office/mailappversionoverrides" xsi:type="VersionOverridesV1_0">
<VersionOverrides xmlns="http://schemas.microsoft.com/office/mailappversionoverrides/1.1" xsi:type="VersionOverridesV1_1">
<Requirements>
<bt:Sets DefaultMinVersion="1.10">
<bt:Set Name="Mailbox" />
</bt:Sets>
</Requirements>
<Hosts>
<Host xsi:type="MailHost">
<!-- Event-based activation happens in a lightweight runtime.-->
<Runtimes>
<!-- HTML file including reference to or inline JavaScript event handlers.
This is used by Outlook on the web and Outlook on the new Mac UI. -->
<Runtime resid="WebViewRuntime.Url">
<!-- JavaScript file containing event handlers. This is used by Outlook on Windows. -->
<Override type="javascript" resid="JSRuntime.Url"/>
</Runtime>
</Runtimes>
<DesktopFormFactor>
<FunctionFile resid="Commands.Url" />
<ExtensionPoint xsi:type="MessageReadCommandSurface">
<OfficeTab id="TabDefault">
<Group id="msgReadGroup">
<Label resid="GroupLabel" />
<Control xsi:type="Button" id="msgReadOpenPaneButton">
<Label resid="TaskpaneButton.Label" />
<Supertip>
<Title resid="TaskpaneButton.Label" />
<Description resid="TaskpaneButton.Tooltip" />
</Supertip>
<Icon>
<bt:Image size="16" resid="Icon.16x16" />
<bt:Image size="32" resid="Icon.32x32" />
<bt:Image size="80" resid="Icon.80x80" />
</Icon>
<Action xsi:type="ShowTaskpane">
<SourceLocation resid="Taskpane.Url" />
</Action>
</Control>
<Control xsi:type="Button" id="ActionButton">
<Label resid="ActionButton.Label"/>
<Supertip>
<Title resid="ActionButton.Label"/>
<Description resid="ActionButton.Tooltip"/>
</Supertip>
<Icon>
<bt:Image size="16" resid="Icon.16x16"/>
<bt:Image size="32" resid="Icon.32x32"/>
<bt:Image size="80" resid="Icon.80x80"/>
</Icon>
<Action xsi:type="ExecuteFunction">
<FunctionName>action</FunctionName>
</Action>
</Control>
</Group>
</OfficeTab>
</ExtensionPoint>
<!-- Can configure other command surface extension points for add-in command support. -->
<!-- Enable launching the add-in on the included events. -->
<ExtensionPoint xsi:type="LaunchEvent">
<LaunchEvents>
<LaunchEvent Type="OnNewMessageCompose" FunctionName="onNewMessageComposeHandler"/>
<LaunchEvent Type="OnNewAppointmentOrganizer" FunctionName="onNewAppointmentComposeHandler"/>
<!-- Other available events -->
<!--
<LaunchEvent Type="OnMessageAttachmentsChanged" FunctionName="onMessageAttachmentsChangedHandler" />
<LaunchEvent Type="OnAppointmentAttachmentsChanged" FunctionName="onAppointmentAttachmentsChangedHandler" />
<LaunchEvent Type="OnMessageRecipientsChanged" FunctionName="onMessageRecipientsChangedHandler" />
<LaunchEvent Type="OnAppointmentAttendeesChanged" FunctionName="onAppointmentAttendeesChangedHandler" />
<LaunchEvent Type="OnAppointmentTimeChanged" FunctionName="onAppointmentTimeChangedHandler" />
<LaunchEvent Type="OnAppointmentRecurrenceChanged" FunctionName="onAppointmentRecurrenceChangedHandler" />
<LaunchEvent Type="OnInfoBarDismissClicked" FunctionName="onInfobarDismissClickedHandler" />
<LaunchEvent Type="OnMessageSend" FunctionName="onMessageSendHandler" SendMode="PromptUser" />
<LaunchEvent Type="OnAppointmentSend" FunctionName="onAppointmentSendHandler" SendMode="PromptUser" />
<LaunchEvent Type="OnMessageCompose" FunctionName="onMessageComposeHandler" />
<LaunchEvent Type="OnAppointmentOrganizer" FunctionName="onAppointmentOrganizerHandler" />
-->
</LaunchEvents>
<!-- Identifies the runtime to be used (also referenced by the Runtime element). -->
<SourceLocation resid="WebViewRuntime.Url"/>
</ExtensionPoint>
</DesktopFormFactor>
</Host>
</Hosts>
<Resources>
<bt:Images>
<bt:Image id="Icon.16x16" DefaultValue="https://localhost:3000/assets/icon-16.png"/>
<bt:Image id="Icon.32x32" DefaultValue="https://localhost:3000/assets/icon-32.png"/>
<bt:Image id="Icon.80x80" DefaultValue="https://localhost:3000/assets/icon-80.png"/>
</bt:Images>
<bt:Urls>
<bt:Url id="Commands.Url" DefaultValue="https://localhost:3000/commands.html" />
<bt:Url id="Taskpane.Url" DefaultValue="https://localhost:3000/taskpane.html" />
<bt:Url id="WebViewRuntime.Url" DefaultValue="https://localhost:3000/commands.html" />
<!-- Entry needed for Outlook on Windows. -->
<bt:Url id="JSRuntime.Url" DefaultValue="https://localhost:3000/launchevent.js" />
</bt:Urls>
<bt:ShortStrings>
<bt:String id="GroupLabel" DefaultValue="Contoso Add-in"/>
<bt:String id="TaskpaneButton.Label" DefaultValue="Show Taskpane"/>
<bt:String id="ActionButton.Label" DefaultValue="Perform an action"/>
</bt:ShortStrings>
<bt:LongStrings>
<bt:String id="TaskpaneButton.Tooltip" DefaultValue="Opens a pane displaying all available properties."/>
<bt:String id="ActionButton.Tooltip" DefaultValue="Perform an action when clicked."/>
</bt:LongStrings>
</Resources>
</VersionOverrides>
</VersionOverrides>
Outlook on Windows uses a JavaScript file, while Outlook on the web and on the new Mac UI use an HTML file that can reference the same JavaScript file. You must provide references to both these files in the Resources node of the manifest as the Outlook platform ultimately determines whether to use HTML or JavaScript based on the Outlook client. As such, to configure event handling, provide the location of the HTML in the <Runtime> element, then in its Override child element provide the location of the JavaScript file inlined or referenced by the HTML.
Tip
- To learn about runtimes in add-ins, see Runtimes in Office Add-ins.
- To learn more about manifests for Outlook add-ins, see Outlook add-in manifests.
Implement event handling
You have to implement handling for your selected events.
In this scenario, you'll add handling for composing new items.
From the same quick start project, create a new folder named launchevent under the ./src directory.
In the ./src/launchevent folder, create a new file named launchevent.js.
Open the file ./src/launchevent/launchevent.js in your code editor and add the following JavaScript code.
/* * Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. * See LICENSE in the project root for license information. */ function onNewMessageComposeHandler(event) { setSubject(event); } function onNewAppointmentComposeHandler(event) { setSubject(event); } function setSubject(event) { Office.context.mailbox.item.subject.setAsync( "Set by an event-based add-in!", { "asyncContext": event }, function (asyncResult) { // Handle success or error. if (asyncResult.status !== Office.AsyncResultStatus.Succeeded) { console.error("Failed to set subject: " + JSON.stringify(asyncResult.error)); } // Call event.completed() after all work is done. asyncResult.asyncContext.completed(); }); } // IMPORTANT: Remember to map the event handler name specified in the manifest's LaunchEvent element to its JavaScript counterpart. // 1st parameter: FunctionName of LaunchEvent in the manifest; 2nd parameter: Its implementation in this .js file. Office.actions.associate("onNewMessageComposeHandler", onNewMessageComposeHandler); Office.actions.associate("onNewAppointmentComposeHandler", onNewAppointmentComposeHandler);Save your changes.
Important
Windows: At present, imports aren't supported in the JavaScript file where you implement the handling for event-based activation.
Tip
Event-based add-ins running in Outlook on Windows don't run code included in the Office.onReady() and Office.initialize functions. We recommend adding your add-in startup logic, such as checking the user's Outlook version, to your event handlers instead.
Update the commands HTML file
In the ./src/commands folder, open commands.html.
Immediately before the closing head tag (
</head>), add a script entry to include the event-handling JavaScript code.<script type="text/javascript" src="../launchevent/launchevent.js"></script>Save your changes.
Update webpack config settings
Open the webpack.config.js file found in the root directory of the project and complete the following steps.
Locate the
pluginsarray within theconfigobject and add this new object at the beginning of the array.new CopyWebpackPlugin({ patterns: [ { from: "./src/launchevent/launchevent.js", to: "launchevent.js", }, ], }),Save your changes.
Try it out
Run the following commands in the root directory of your project. When you run
npm start, the local web server will start (if it's not already running) and your add-in will be sideloaded.npm run buildnpm startNote
If your add-in wasn't automatically sideloaded, then follow the instructions in Sideload Outlook add-ins for testing to manually sideload the add-in in Outlook.
In Outlook on the web, create a new message.

In Outlook on the new Mac UI, create a new message.

In Outlook on Windows, create a new message.

Debug
As you make changes to launch-event handling in your add-in, you should be aware that:
- If you updated the manifest, remove the add-in, then sideload it again. If you're using Outlook on Windows, then close and reopen Outlook.
- If you made changes to files other than the manifest, close and reopen Outlook on Windows, or refresh the browser tab running Outlook on the web.
While implementing your own functionality, you may need to debug your code. For guidance on how to debug event-based add-in activation, see Debug your event-based Outlook add-in.
Runtime logging is also available for this feature on Windows. For more information, see Debug your add-in with runtime logging.
Note
Outlook on Windows: If you're running your add-in from localhost and see the error "We're sorry, we couldn't access {your-add-in-name-here}. Make sure you have a network connection. If the problem continues, please try again later.", you may need to enable a loopback exemption.
Close Outlook.
Open the Task Manager and ensure that the msoadfsb.exe process is not running.
Set the loopback exemption in an elevated prompt.
If you're using
https://localhostand port 3000 (the default configuration), run the following command.call %SystemRoot%\System32\CheckNetIsolation.exe LoopbackExempt -a -n=1_https___localhost_300004ACA5EC-D79A-43EA-AB47-E50E47DD96FCIf you're using
http://localhostand port 3000, run the following command.call %SystemRoot%\System32\CheckNetIsolation.exe LoopbackExempt -a -n=1_http___localhost_300004ACA5EC-D79A-43EA-AB47-E50E47DD96FC
Note: If you're not using the default port 3000, replace it in the command with your actual port number.
Restart Outlook.
Deploy to users
You can deploy event-based add-ins by uploading the manifest through the Microsoft 365 admin center. In the admin portal, expand the Settings section in the navigation pane then select Integrated apps. On the Integrated apps page, choose the Upload custom apps action.

Important
Event-based add-ins are restricted to admin-managed deployments only. Users can't activate event-based add-ins from AppSource or in-app Office Store. To learn more, see AppSource listing options for your event-based Outlook add-in.
Important
Add-ins that use the Smart Alerts feature can only be published to AppSource if the manifest's SendMode property is set to the SoftBlock or PromptUser option. If an add-in's SendMode property is set to Block, it can only be deployed by an organization's admin as it will fail AppSource validation.
Event-based activation behavior and limitations
Add-in launch-event handlers are expected to be short-running, lightweight, and as noninvasive as possible. After activation, your add-in will time out within approximately 300 seconds, the maximum length of time allowed for running event-based add-ins. To signal that your add-in has completed processing a launch event, your associated event handler must call the event.completed method. (Note that code included after the event.completed statement isn't guaranteed to run.) Each time an event that your add-in handles is triggered, the add-in is reactivated and runs the associated event handler, and the timeout window is reset. The add-in ends after it times out, or the user closes the compose window or sends the item.
If the user has multiple add-ins that subscribed to the same event, the Outlook platform launches the add-ins in no particular order. Currently, only five event-based add-ins can be actively running.
In all supported Outlook clients, the user must remain on the current mail item where the add-in was activated for it to complete running. Navigating away from the current item (for example, switching to another compose window or tab) terminates the add-in operation. The add-in also ceases operation when the user sends the message or appointment they're composing.
When developing an event-based add-in to run in the Outlook on Windows client, be mindful of the following:
- Imports aren't supported in the JavaScript file where you implement the handling for event-based activation.
- Add-ins don't run code included in
Office.onReady()andOffice.initialize. We recommend adding any startup logic, such as checking the user's Outlook version, to your event handlers instead.
Some Office.js APIs that change or alter the UI aren't allowed from event-based add-ins. The following are the blocked APIs.
- Under
Office.context.auth:getAccessTokengetAccessTokenAsyncNote
OfficeRuntime.auth is supported in all Outlook versions that support event-based activation and single sign-on (SSO), while Office.auth is only supported in certain Outlook builds. For more information, see Enable single sign-on (SSO) in Outlook add-ins that use event-based activation.
- Under
Office.context.mailbox:displayAppointmentFormdisplayMessageFormdisplayNewAppointmentFormdisplayNewMessageForm
- Under
Office.context.mailbox.item:close
- Under
Office.context.ui:displayDialogAsyncmessageParent
Requesting external data
You can request external data by using an API like Fetch or by using XMLHttpRequest (XHR), a standard web API that issues HTTP requests to interact with servers.
Be aware that you must use additional security measures when using XMLHttpRequest objects, requiring Same Origin Policy and simple CORS (Cross-Origin Resource Sharing).
A simple CORS implementation:
- Can't use cookies.
- Only supports simple methods, such as
GET,HEAD, andPOST. - Accepts simple headers with field names
Accept,Accept-Language, orContent-Language. - Can use the
Content-Type, provided that the content type isapplication/x-www-form-urlencoded,text/plain, ormultipart/form-data. - Can't have event listeners registered on the object returned by
XMLHttpRequest.upload. - Can't use
ReadableStreamobjects in requests.
Note
Full CORS support is available in Outlook on the web, Mac, and Windows (starting in version 2201, build 16.0.14813.10000).
See also
Feedback
Submit and view feedback for