Imagine you want to know the sentiment of an email without reading it. This can be useful if you want to ignore negative emails for certain parts of the day. I have built a solution for that, by integrating Azure Machine Learning in an Office Outlook Add-In. Every time you read an email, it processes the body, sends it to Azure, and displays if it is negative or positiveThe end result is:

                                            

 

I had already planned this blog post a month ago, but at that time it was not working in client-side only applications; the API end point was not CORS enabled. This has now been fixed by Microsoft, so I can use this from my Outlook Add-In without any server side component.

Step 1 : Set up Azure Machine Learning Cognitive Services

The first thing you need to do, is register your application to get an API key. Go to the new Azure portal (http://portal.azure.com) and add a new resource. Search for Cognitive Services API, click it, select Text Analytics API, and copy the key to your clipboard:

Search for Cognitive Services API

Select Text Analytics

Copy the API Key

Step 2: Create the Office Add-in

Now you’ve got access to the Text Analytics API, you can create the Office Add-In. Open Visual Studio, click File => New Project, and choose App for Office. Give it a useful name and location, and click OK.

Select that you want a Mail app, and in the next screen select that it should appear in the Read Email Form.

The next step is to integrate the Text Analytics API in the application. I’ve implemented it as follows, and I’m referring to the source code on GitHub.

  1. On application load, the body of the email is retrieved. See getBody()
  2. This body is sent as one string to the Text Analytics API. See processBody()

And that’s it! Run it, open an email, click on the app, and after a second or two you will see whether you may want to ignore the email or not.