Wednesday, May 09, 2007


Integrate your Java agenda and ICalendar clients (Outlook) with iCal4j


This post concerns integrating a calendar/agenda you created in your Java application with external clients. It is a relevant feature, because applications are not released in a void, but in a world where people already use several applications, among which often there is a calendar client, typically Microsoft Outlook, sometimes also integrated with Exchange Server. Then there are all the non-Microsoft people, with several different clients and tools (see here for a list). So if you build a group calendar management, by making it interact with the agenda clients you will be lowering considerably the adoption barrier.

What's nice of the presented solution is that
In particular it requires just development effort, but no investment in expensive components.

Your Ja
va application
We use Teamwork as example application which has to be integrated. We assume that you have built a solution to keep track in Java of your team's calendar, managing also recurrent events of the different kinds, which is the hardest part: you have to manage daily, weekly, monthly and yearly recurrences, answering fast to questions like "when will the two appointments 'all 4th of month' and 'every Tuesday every two weeks' next intersect? Outlook does all of this, so you need to provide a formalization in your app to synch with it. People (or "resources") involved will be identified by their e-mail in he synch process, and actually this is what Outlook does when you "invite" resources to join meetings.

A basic free tool which you should use is the iCal4j API, through which you will get Java objects modeling ICalendar messages. In our implementation, we had to add a "fake" property to the set provided by iCal4j because of problems with the "CN=..." format, but this is a side detail.

The flow of group meetings creation, editing and approval can go in several directions, and you have to handle all of them.

Create event in Teamwork and send copy to clients

For this, after saving its internal event, your application must send an e-mail to every participant, containing the V-event generated with iCal4J.

You will put the organizer of the event, and the attendees. Set as "UID" of the V-event your event id.

To make Outlook recognize it as an calendar event, put in the mail header


and Outlook will recognize it, presenting the mail received as in the picture.

The appointment will be put in Outlook's calendar when received, and it will be possible to accept them or not.

Notice that if you update an event in your app, and resend it, Outlook will recognize it as an instance of the preceding event, and automatically update the event - (very nice!); this you get by setting the UID field.

Create event in Outlook and make your app aware of this

We did this simply by making our application capable of downloading e-mail. Then when you create your appointment in Outlook, you just "send" it to your app, by having among the attendees the e-mail of your app. You need a scheduled mail download (and hence a job handler), and to parse the received relevant string body part in a V-event, which too is provided by the Ical4j API: in particular, you have to consider the cases

Method.REQUEST.equals(iCalendar.getMethod()) ...

and by working on the V-event UID you can decide whether to create or update an event in your web-app, which will be the final step. To recognize the e-mail received as one relative to calendar, look at the content type which will be "text/calendar". Notice that you will also receive "DECLINED" events, in which case you must remove that attendee from your event.

The outline above can proceed further by handling people who want to remove themselves from event. Then it is natural to proceed in the integration by exporting contacts from the mail client to your application; this is exactly how we proceeded in Teamwork's case, but this is another matter.

More can be found at .

Microsoft Outlook and Exchange Server are (c) Microsoft Corporation. Mozilla Thunderbird is (c) the Mozilla Corporation. iCal4J is Copyright (c) 2006, Ben Fortuna. See


Comments: Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?