Outlook OnSend and Dialog Sample

As promised, I have created a GitHub repository for the sample I blogged about earlier. Here is the repository:

https://github.com/davecra/outlook-sample-1

This includes three items of interest:

  1. The OnSend event, implemented in the simplest of ways to demonstrate bare bones how to get it to work.
  2. The displayDialogAsync with the inline frame (displayInFrame) option. I will blog about this in the future as well.
  3. A project build by Yo Office and published per my blog post here.

What this sample add-in does is pops up a dialog box anytime you press Send on an email with a question: “Are you sure?” If you click Yes, it sends, if you click “no” is blocks the send. Here is what that dialog looks like:

dialog

If you have followed the steps from my Yo Office post, you will be able to open the project in VS Code, and from the terminal, launch it with:

npm start

Next, you will need to follow the steps to enable the OnSend policy in your account and then you will need to install/sideload the manifest. From there you will not see any appearance of the add-in at all, until you press the Send button.

NOTE: At the point I first tested it on June, 13th, 2017, there is a KNOWN ISSUE with the certificates created fro a “yo office” build. If you have not resolved the certificates issue you will be able to start the project in Node.js, but the add-in will fail to run. You need to perform the steps outlined here to correct it:

https://github.com/OfficeDev/generator-office/issues/244

8 thoughts on “Outlook OnSend and Dialog Sample”

  1. Thanks! Very useful article.
    I’m not very confident with Javascript and would rather use C# code behind for dialog page. Is it a good idea to use an aspx/cshtml page with server side processing? I realize that it puts more load on the web server that hosts the add-in and that the add/in might be slightly less responsive, but is that even a sensible option?

  2. Thanks! Very useful article.
    I’m not very confident with Javascript and would rather use C# code behind for dialog page. Is it a good idea to use an aspx/cshtml page with server side processing? I realize that it puts more load on the web server that hosts the add-in and that the add/in might be slightly less responsive, but is that even a sensible option?

    1. I have not tried an ASPX page, but you MUST have some JavaScript that runs client side:
      1) You have to have the Office.initialize() so that Office is initialized and connects to the libraries properly.
      2) In order to return control back to the caller, you must issue a messageParent() when you want to leave the dialog code.
      For rendering purposes and interaction on the page (such as validation) between those two points, I would assume ASPX would work fine. Responsiveness might not be as bad as assumed. But if your dialog needs to get any data from the Object Model, such as the subject line, or the body text or x-headers, you will have to issue client side code to go grab that.

      1. You need to make sure that you have the URL specified in the AppDomains section of your manifest or you will get CORS errors:

        https://localhost:44349

        It needs both the URL and the port. And make sure the port is the same, correct port you are seeing in the error.

      2. Thanks! That helped. I was also missing authorization token which needs to be passed in request headers when calling the web service.

Leave a Reply