Monday, November 15, 2004

Gathering Exchange Appointments Programatically

I'm starting to look at one more set of social network data: meeting invitations. One of the nice things about my organization is that there is a culture of open calendars. Generally speaking, calendars are not private unless there is a compelling reason. This is at the lower levels of the organization. I think this habit may be very different among the top executives. (And, just checking, it is -- there is nothing on the CEO's calendar, nor on the program manager's calendar)

In any case, the problem quickly became finding a way to programatically grab appointment information from Exchange. Luckily, I was at a gathering of a bunch of collaborative computing types, and especially, MSR types. So I asked, figuring this would be a no-brainer. As it turns out, it's a little harder than I expected. I was first cautioned by Gina to avoid MAPI ("with a ten foot pole"), and pushed towards WebDAV. THe only problem with WebDAV is that it appears that the local install of Exchange doesn't support WebDAV. Or I'm not smart enough to implement a client to be able to do it properly. Or I can't figure out what my Domain\Username is formally. (Mark.j.handel? hh292c? hh292ca?) Collaboration Data Objects (CDOs) don't work, since they have to run on the Exchange server. Which brings me back to MAPI. Of course, the Perl MAPI module doesn't do what I want it to do (it sends e-mail, and that's about it.)

Then, a sudden insight. You can use Visual Basic for Applications to script Outlook. (As the many Outlook viruses have shown.) In fact, it's pretty easy. Here's the code to do it:

Set olApp = CreateObject("Outlook.Application")
Set olNS = olApp.GetNamespace("MAPI")

Set user = olNS.CreateRecipient("Handel, Mark J")
Set fol = olNS.GetSharedDefaultFolder(user, 9)
Set itms = fol.Items

For i = 1 To itms.Count()
WScript.StdOut.write itms(i).Start & "|" & _
itms(i).End & "|" & _
itms(i).Subject & "|"

Set recips = itms(i).Recipients
For j = 1 to recips.Count()
WScript.StdOut.write recips(j).Name & ";" & _
recips(j).Type & "|"


(Of course, this code does not include error checking, nor does it dump the full range of appointment information available. But it's good enough for a short blog entry. If you want the full code, as well as "filters" to get it into neato or dot format, drop me an e-mail.)


Post a Comment

<< Home