Hook, Line, and Sink’r

So I recently helped a customer develop a managed Exchange Store Sink. One thing I noticed is that it doesn't seem to be any public step-by-step instructions for the Exchange-development impaired, so I decided to at least give a high level HOWTO on doing this. So here ya go…

Step 1…The first thing I would suggest doing is writing your code (or as much as possible) in a console or windows application and make sure that as much of the functionality of your code is tested using one of these application types. It's a lot harder to debug a store sink running in a COM+ Application than it is to debug a .net console app.

Step 2…Decide what type and what scope of sink you need. For most people, you are going to want to develop an Asynchronous sink. These will fire events (OnSave and OnDelete) after the change has been made, while Synchronous events (OnSyncSave, OnSyncDelete) occur during the change. The synchronous events, while tempting, should be avoided if an asynchronous sink will do the job. When running a synchronous sink, the Exchange store has to halt operation and wait for your code to finish before continuing its normal processing. If you plan to do something that could take a good bit of time (in processor time, not Congress time), and you don't need to prevent the action from taking place, you should use an asynchronous store.

For scope, you have the options for exact (just this folder), shallow (me and my children), or deep (me and my descendants).

Step 3…Build your sink. Basically, you want to follow these steps to build your sink. The things to keep in mind here are that you can copy exoledb.dll to your development machine to build your interop assemblies. Also, pay attention when building your sink about the flags passed in as this is your key to deciding whether to act or not. The flags describe what triggered the event to occur.

Step 4…Once you have your sink built, copy it and the .tlb file and the "Interop" assemblies over to the Exchange server you want to register it on. Place it in a file where it will live. Remember, it's bad karma to move a COM dll.

Step 5…Register the assembly using regasm (in your Framework directory) on your Exchange server. Just open a command prompt and navigate (cd) to the %systemroot%\Microsoft.NET\Framework\v1.1.4322 folder. Then call

regasm yourassembly.dll

That will register your assembly in the registry.

Step 6…Create a COM+ application and add your component. On your Exchange server, Go to Administrative Tools and open the Component Services snap-in. Drill into "Component Services" > Computers > My Computer > COM+ Applications. Right click on the COM+ Applications folder and say New > Application. Just create an empty application and call it whatever you want. Once you go into the properties of the application, set it to use an account whose you want your code to run in. This is the "Impersonation" idea you're used to from .net land.

Once you have your Application created, drill into it and right click on Components and click New > Component. Choose to install a new component and point to your dll or tlb file. This will add your component to this COM+ Application so that whenever your component is initialized, it is done in the context of this application.

Step 7…Register your sink on the folder of interest. There are quite a few ways to do this.

Remember to use the scope you decided upon earlier (deep, exact, or shallow).

Once your sink is registered, you're done!

Congrats. Wanna cookie?

Skip to main content