Validating a company email alias with Outlook

Most of the process related tools we use (bug databases, work items, test cases, etc), will keep track of owners by their email alias. Unfortunately, if someone's alias changes (such as transitioning from contractor to Full Time) or they leave the company, then items assigned to them become orphaned. Using the Outlook COM interface, we can check an email account to ensure it exists in our address book. This information could then be used to generate a report of which items need to be re-assigned. Looking at the below JavaScript, we show how to do a sample lookup:

 

checkAlias.js

var outlook = WScript.CreateObject("Outlook.Application");

 

function CheckAlias(alias)

    {

    var recipient = outlook.Session.CreateRecipient(alias);

   

    // attempt to look up the entry in the address book

    if(!recipient.Resolve())

        return false;

 

    var user = recipient.AddressEntry();

 

    // if the entry did not resolve to a real user,

    // then we just get back exactly what we passed in,

    // otherwise we get back the user's name

    if(user.Name() == alias)

        return false;

 

    return true;

    }

 

outlook.Quit();

 

Note that invoking Outlook through the COM interface may bring up a security dialog, giving the physical user the option to allow or disallow the script execution.

 

To take this tool a step further, you could look at some of the other available methods and properties off of the recipient's AddressEntry to identify users who still work at the company but have moved to a different group or project. Unfortunately, some of the interesting properties are marked "hidden", so they aren't as obvious as would be helpful, such as the .Manager property which returns another AddressEntry object. All the hidden entries can be discovered using a Type Library viewer. And if you want to browse the entire Outlook Type Library, look in MSOUTL.OLB (it may need to be renamed to .dll or .exe for some tools to fully appreciate the goodness).

MSDN References

Outlook.Application

Outlook.Recipient