Name: Outlook-Add-in-LinkRevealer
Owner: Office Developer
Description: This Outlook add-in demonstrates how to find and parse all links in the body of an email.
Created: 2015-08-27 20:08:49.0
Updated: 2018-03-27 04:12:47.0
Pushed: 2018-01-31 20:28:32.0
Size: 1416
Language: JavaScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Table of contents
In this sample we show you how to use the JavaScript API for Office to create an Outlook add-in that parses the body of an email looking for hyperlinks. The following is a picture of the scenario in question (in the Outlook Web App).
This add-in is configured to use add-in commands, so when you're reading your email in the desktop client, you launch the add-in by choosing this command button in the ribbon:
It has happened to us all during our email lifetimes - we receive what looks like a regular email from what seems like a trusted source that contains hyperlinks. We click on one of those links without thinking and are then at risk of having our machine, our systems or business compromised. This is a classic phishing scenario wherein the hyperlinks in an email are not what they seem. This sample shows an alternative way of verifying hyperlinks. Instead of hovering over a link to see what the real target URL behind the link text is, and perhaps risking an accidental click on said link, this add-in finds all links in an email and displays them in a decomposed format of link text and link URL. In this way, the user can see clearly what address is behind the link text. The sample goes a little further. If a link has a URL as the link text and that URL doesn't match the underlying href of the link, the link is flagged in red in the add-in to make sure the user sees this potentially phishy link.
This sample requires the following:
This solution was created in Visual Studio. It consists of two projects - LinkRevealer and LinkRevealerWeb. Here's a list of the key files within those projects.
`LinkRevealer.xml
` The manifest file for the Word add-in.`Home.html
` The HTML user interface for the Word add-in.`Home.js
` The JavaScript code used by Home.html to interact with Word using the JavaScript for Office API.The core logic of this sample is in the `Home.js
` file in the LinkRevealerWeb project. Once the add-in is initialized, the `getAsync()
` method of the Body object is used to retrieve the body of the email in HTML format. When this asynchronous operation is completed, our callback function, processHtmlBody, is invoked. This function first loads the retrived body content into a DomParser. This object tree is then parsed using the getElementsByTagName(“a”) method to find all hyperlinks. Finally, each hyperlink is displayed on the UI and analyzed to see if any links are phishy.
Using body.getAsync() to retrieve the body of an email has numerous advantages over earlier solutions. In previous versions of Office.js, the only way to get the body of an email in a read scenario was to call `makeEWSRequest
` on the mailbox object. Not only was the contruction of this SOAP request more involved, but it also required an add-in to have ReadWriteMailbox permissions. The getAsync() solution only requires that the add-in has ReadItem permissions.
`LinkRevealer.sln
` file in Visual Studio.We encourage you to contribute to our samples. For guidelines on how to proceed, see our contribution guide
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.
Copyright (c) 2015 Microsoft. All rights reserved.