Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Drag and drop functionality allows users to seamlessly transfer messages and file attachments from their mailbox directly into your add-in's task pane. With the drag-and-drop feature, users can perform the following without leaving the Outlook client.
- Import files into a document management interface for processing or archiving.
- Upload customer records and communication logs to a customer relationship management (CRM) system for tracking.
- Convert a file into another format.
Supported Outlook clients and surfaces
The following table outlines the Outlook clients that support the drag-and-drop feature and the APIs used to implement it.
Outlook client | Support for drag and drop | Implementation method | Supported Outlook surfaces |
---|---|---|---|
Outlook on the web | Supported | Office.js API (Office.EventType.ItemDraggedAndDropped) |
|
New Outlook on Windows | Supported | Office.js API (Office.EventType.ItemDraggedAndDropped) |
|
Classic Outlook on Windows | Supported | HTML Drag and Drop API |
|
Outlook on Mac | Supported | HTML Drag and Drop API |
|
Outlook on iOS | Not supported | Not applicable | Not applicable |
Outlook on Android | Not supported | Not applicable | Not applicable |
For information on which file types and scenarios are supported, see Feature behavior and limitations.
Implement the drag-and-drop feature
The drag or drop event occurs when the mouse pointer enters an add-in's task pane. Handling the drag and drop events differs depending on the Outlook client. Select the tab for your applicable client.
Note
This section assumes that a task pane has already been implemented for your Outlook add-in. For information about task panes, see Add-in commands. To create an add-in sample that already implements a task pane, follow the Outlook quickstart.
In Outlook on the web and the new Outlook on Windows, create a handler in your JavaScript file for the Office.EventType.ItemDraggedAndDropped event using the Office.context.mailbox.addHandlerAsync method. When the ItemDraggedAndDropped
event occurs, the handler receives a DragAndDropEventArgs object so that you can identify when a user drags an item over the task pane, when they drop the item into the task pane, and what data is associated with the item. Depending on whether a drag or drop event occurred, the dragAndDropEventData property of the DragAndDropEventArgs
object returns a DragoverEventData or DropEventData object. These objects provide information on the position of the mouse pointer and the data being transferred to the task pane.
When messages are dragged to the task pane, they're dropped as .eml files. Attachments that are dropped retain their current format. For a list of supported types, see Supported item types.
The following example shows how to implement the drag-and-drop feature.
// Handle the ItemDraggedAndDropped event.
Office.context.mailbox.addHandlerAsync(
Office.EventType.ItemDraggedAndDropped,
(event) => {
console.log(`Event occurred: ${event.type}`);
const eventData = event.dragAndDropEventData;
// Get the file name and the contents of the items dropped into the task pane.
if (eventData.type == "drop") {
const files = eventData.dataTransfer.files;
files.forEach((file) => {
const content = file.fileContent;
const name = file.name;
// Add operations to process the item here, such as uploading the file to a CRM system.
});
}
},
(asyncResult) => {
if (asyncResult.status === Office.AsyncResultStatus.Failed) {
console.error("Failed to add event handler:", asyncResult.error.message);
return;
}
console.log("Event handler added successfully.");
}
);
Feature behavior and limitations
Supported item types
The following file types are supported by the drag-and-drop feature.
- Messages: Messages in the .eml or .msg format. Additionally, the following types of encrypted messages are also supported.
- Messages encrypted using the S/MIME (Secure/Multipurpose Internet Mail Extensions) protocol.
- Messages protected by Information Rights Management (IRM) with a sensitivity label that has the Allow programmatic access custom policy option set to
true
.
- Attachments: File types supported by Outlook. For guidance, see Blocked attachments in Outlook.
Tip
For information on the types of data that the HTML Drag and Drop API supports, see Recommended drag types.
Supported scenarios
The following table identifies which scenarios support the drag-and-drop feature in Outlook.
Scenario | Supports drag and drop |
---|---|
Drag and drop a message or attachment from the Reading Pane to an add-in's task pane in the same window | Supported |
Drag and drop a message or an attachment from the Reading Pane to a task pane open in a different window | Supported |
While a message is open in a different window, drag and drop an attachment contained in the message to a task pane open in main window of the Outlook client | Supported |
While a message is open in a different window, drag and drop an attachment contained in the message to a task pane in the same window | Supported |
Drag and drop multiple attachments at the same time | Supported |
Drag and drop multiple messages at the same time | Supported |
Drag and drop a mix of multiple messages and attachments at the same time | Not supported |
Drag and drop a file from a task pane to the mailbox | Not supported |
Drag and drop a file from the desktop to an add-in's task pane in Outlook | Depends on the drag-and-drop API used.
|
Drag and drop an item from another mailbox | Not supported |
Drag and drop an item across two instances of the main window of the Outlook client | Not supported |
Drag and drop an item across different Outlook clients | Not supported |
Limitations
Be aware of the following limitations when implementing drag and drop in your add-in.
- If a user navigates to another mail item while an item that's been dragged to an add-in's task pane is being processed, the behavior varies depending on whether the task pane is pinned. If the task pane is pinned, processing isn't interrupted. Otherwise, processing fails. We recommend including progress indicators and displaying error messages for user awareness.
- Inline image attachments and links in messages can't be dropped into the task pane. For guidance on supported items, see Supported item types.
See also
Office Add-ins