Using Events with Microsoft Exchange |
Exchange is very different in the way it exposes events - you do not use a regular type library (CDO.DLL) and run com2java on it, etc. If you noticed, the type library contained in CDO.DLL does not have any declarations for exposed events. Events in the Exchange Server are actually run as a separate service known as the Microsoft Exchange Event Service (EVENTS.EXE). Two things of note:
1. The Event Service can only monitor folders stored on an Exchange server. It will not monitor folders stored on the local machines of users. For that, you'll need the Outlook type library instead (which contains events you can hook into) and not CDO.DLL.
2. The Event Service fires events asynchronously rather than synchronously in the context of the Exchange Information Store, so the Information Store won't block your event script, other processes, or people from working on items in the folder if the script hasn't run yet.
The general idea
The Event Service monitors changes to a folder and triggers an event if such change occurs. A change could either be one of the following:
- A new item is added to a folder (e.g. an new mail arrives in your inbox)
- An existing item is modified (e.g. the business phone number of a contact item is changed)
- An item is deleted
- Scheduled events (e.g. events that are triggered every Saturday at 1:00 am)
Once the Event Service realizes that a change has occurred, it fires an event. It then looks for a corresponding event handler in the folder. The Exchange Event Service ships with one pre-built event handler, named the Exchange Event Scripting Agent that you can bind t