An Outlook Add-in that provides users the ability to share OneDrive links to email recipients.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Microsoft Outlook Add-in Sharing to OneDrive

Users can now share a OneDrive item directly from within an Outlook add-in. In this sample, we show you how to use the JavaScript API for Office, and the OneDrive API to create a Microsoft Outlook Add-in that displays which email recipients have permission to view the OneDrive link in the message body. If there are recipients that don't have the proper permission to view the link(s), the user will have the option to grant permissions to selected recipients.

With the OneDrive shares API, you can programmatically get permissions for an item by using the item's link. You can then use the same shares API, with action.invite, to share the URL with email recipients.

Table of Contents


This sample requires the following:

Note: This sample currently only works with consumer OneDrive service.

Configure the project

  1. Get a token from the OneDrive developer site. To get a token, go to OneDrive authentication and sign in and click Get Token. Copy the token, which is after the text Authentication: bearer and save it to a text file. This token is valid for one hour, and gives you read/write access to the signed in user's OneDrive files. You'll be required to sign in to your personal OneDrive.
  2. Open the solution file OutlookAddinOneDriveSharing.sln and in the \app\authentication.config.js file, paste the token, like this:
TOKEN = '<your_token>';
  1. In Solution Explorer, click the OutlookAddinOneDriveSharing project and in the Properties window, change Start Action to Office Desktop Client.

  2. Right-click the OutlookAddinOneDriveSharing project and choose Set as StartUp Project.

  3. Close Outlook desktop client.

Run the project

Press F5 to run the project. You'll be prompted to enter an email and password to use for running Outlook. Enter your Exchange email and password. Note This may be different from your personal OneDrive account email and password.

Once the Outlook desktop client has started, click New Email to compose a new message.

Important If you weren't prompted to accept the installation for the IIS Express Development Certificate, navigate to Control Panel | Add/Remove Programs and choose IIS Express. Right-click and choose Repair. Restart Visual Studio and open the OutlookAddinOneDriveSharing.sln file.

This add-in uses add-in commands, so you launch the add-in by choosing this command button on the ribbon:

Check access command button on the ribbon

A task pane appears with the list of recipients. The list is divided by who has permission to view the link, and who doesn't. Note Any time you add or remove recipients, or change the link, click the command button again to refresh the list.

To get a OneDrive link, sign in to your OneDrive account at and choose one of your files. Copy the link for that file and paste it into the body of the email message.

Understand the code

  • app.js - In app.js, a global object of recipients is created by using the Office.context.mail.item.getAsync to get recipients from the message. Links are obtained in the same way, with Office.context.mail.item.body.getAsync.
  • onedrive.share.service.js - An object to handle requests to the OneDrive API. This object includes:
    • A link property to maintain links.
    • A request method to send requests to the OneDrive API endpoint, and to use the shares and permissions API.
    • A UI object to render the display to the task pane.
  • render.controller.js - An object to control the display in the task pane.


  • The sample checks only the first link in the message body.
  • You must use a personal OneDrive account to get the token.
  • If you are using an Outlook account for your personal OneDrive account and it hasn't been migrated to Office 365, sharing may not work. To check if your email account was migrated, sign in to and if the upper left hand corner says, it's not migrated.

Questions and comments

We'd love to get your feedback about the Outlook Add-in Sharing to OneDrive sample. You can send your feedback to us in the Issues section of this repository. Questions about Office 365 development in general should be posted to Stack Overflow. Make sure that your questions are tagged with [Office365] and [API].

Additional resources


Copyright (c) 2016 Microsoft. All rights reserved.

This project has adopted the Microsoft Open Source Code of Conduct. For more information, see the Code of Conduct FAQ or contact with any additional questions or comments.