Updated Outlook Web Add-in Sample

I will be presenting a demo at the MVP Summit 2018 for Outlook and also helping with some labs in Excel on the OfficeJS platform. In preparation, I updated my Outlook Sample on my GitHub. This sample was created in VSCode via a Yeoman template.

What the add-in does is a check of all users on the To/CC/BCC line, splits apart any groups (or groups in groups) and then checks to see if any of the user emails are external to your domain. If any external users are found it prompts you with dialog asking if you are sure you want to send:

Outlook Blocking Add-in

The updated add-in demonstrates:

  • The OnSend event
  • The use of dialogs
  • And the newly added ExpandDL function for Exchange Web Services through the makeEwsRequestAsync() call.

In this sample, I am using both of my libraries:

  • easyEws – to help with the ExpandDL call. Updated in a previous post.
  • OfficeJS.dialogs – to display the dialog you see above.

I also had to create a set of asynchronous functions and asynchronous recursive function calls to perform this work – which got a tad complex. For now all the code is in the function-file.js, but to help with splitting out all recipients and groups I might build this into a new library. For example, here is the function to recursively call itself asynchronously (splitting groups in groups in groups in groups…):


/**
* Splits a group and calls the completed function
*/
function splitGroupsAndFindExternalsRecursivelyAsync() {
if(groups.length == 0) {
// if no groups stop
completedCallback();
} else {
/** @type {string} */
var group = groups.pop();
// call expandGroup to get users
easyEws.expandGroup(group, function(groupUsers) {
groupUsers.forEach(function(groupUser, index){
if(groupUser.MailboxType() == "PublicDL") {
groups.push(groupUser);
} else {
/** @type {string} */
var emailDomain = getDomain(groupUser.Address());
if(emailDomain != domain) {
externals.push(groupUser.Address());
}
}
}); // groupUsers.forEach
splitGroupsAndFindExternalsRecursivelyAsync(); // recursive
}, function(error) {
console.log(error);
// just fail
completedCallback();
}); // easyEws.expandGroup
} // end-if
}

Anyway, I will be demonstrating this add-in and the functionality required at the MVP Summit. So if you are attending, I hope to see you there.

Leave a Reply