Welcome to Exchange Team Blog Sign in | Join | Help

Writing Managed Sinks for SMTP and Transport Events

Summary: This document provides developers an overview of how to write event sinks for SMTP and Transport events in managed code using wrappers that obscure some of the details of communicating with the unmanaged server.

Introduction

Writing event sinks in managed code allows the programmer to make use of the Microsoft® .NET Framework and to more efficiently write the code that is necessary for the sink. Writing managed sinks can be somewhat difficult, however, because event sink interfaces were designed primarily for C++ programmers and are therefore not very easy to use in a language such as C#. In addition, some of the methods that are imported using Tlbimp.exe will not work unless they are modified at the intermediate language (IL) level. However, these inconsistencies in the imported assemblies have been fixed in the events' primary interop assembly (PIA) provided, and other interfaces that were inconvenient to use have also been wrapped so that they are easier to use from managed code.

These managed wrappers wrap each of the methods on the original interfaces and correctly communicate with the unmanaged server. In addition, some of the original methods are exposed as properties instead of pairs of methods. For example, all pairs of Set and Query methods are exposed as properties.

This document assumes that the reader has a working knowledge of the .NET Framework, COM, COM Interop and Microsoft Windows® 2000 SMTP Service Events.

For information about event sinks in general, see Microsoft Windows 2000 SMTP Service Events. As described in that document, sinks can implement a number of interfaces to handle corresponding events on the server. The methods of those interfaces are then called when the appropriate event is triggered and certain parameters are passed in.

How to Write a Managed Event Sink in C#: Step by Step

To write a managed event sink, you must link to the PIA that contains the necessary interfaces and implement the interfaces that correspond to the events that need to be handled. Optionally, you can link to the assembly that contains the easier-to-use wrappers for these interfaces.

Read the rest on MSDN web site...

Pretish Abraham

Published Wednesday, June 16, 2004 2:36 PM by Exchange
Filed Under: , ,

Comments

 

Chris said:

This is a reprint of an MSDN article which is over a year old. It links to a 4 year old article. Not that either of these articles is bad, but most people with a strong interest in writing event sinks will have already seen these. There's not a whole lot of documentation on event sinks which isn't contained either in this article or the links which spread from it.

For those who want more in depth documentation, where do we turn? "Programming Microsoft Outlook and Microsoft Exchange 2003" only manages to devote 3 pages to the subject.
June 16, 2004 4:07 PM
 

Pretish Abraham said:

Chris, is there anything in particular you would like more documentation about? Ill try digging up something.
June 16, 2004 4:36 PM
 

Chris said:

How about a something on writing your own protocol verb both publishing (EHLO) and sending?
June 17, 2004 4:05 PM
 

Mike said:

Has anyone tried the Managed Sinks implementation lately? I tried the step by step implementation on Windows 2003 Server just yesterday. Everything registers both in the COM (by Vstudio) and Events (using smtpreg.vbs) bases , the Managed COM object can instantiate, but alas the SMTP Virtual Server never calls it. Further the inetinfo.exe process never appears to load the assembly containing the event sink. The only thing I see that is weird is that the COM Object viewer does not show the Sink as having implemented ISmtpInCommandSink. Could the Interop DLL provided by the article with the patch have some bugs in it? Any suggestions greatly appreciated.
June 22, 2004 9:27 AM
 

Nino Bilic said:

Mike,

I have looked and asked around and also checked with the article author etc... we are not aware of any problems or bugs that would explain what you are seeing. I'd ask you to open up a case with out messaging dev support people to look into this as it is not expected. It is hard to give you more details without asking for a lot more detail :)
June 22, 2004 3:48 PM
 

Philip Colmer said:

There are definitely some steps missing from the documentation in order to get from building the source into a working system. Perusal of the exchange.development newsgroup reveals that you need to do "regasm /codebase" to get the DLLs installed into the GAC.

Also, the documentation could do with expanding on the other interfaces. For example, is it possible to write a managed sink for the transport interface? If so, how - because the parameters are very different from the Inbound & Outbound sinks.
June 23, 2004 2:26 AM
 

Philip Colmer said:

Also, can we have more details on what you can do with the context, e.g. how do you tell the outbound SMTP sink to not send the message that you are currently looking at?

Or is this documented somewhere else and it needs cross-referencing from this document?
June 23, 2004 9:00 AM
 

prasad said:

Hi,

I have read the article yesterday itself and trying to implement it...still couldn't do it.
I couldn't see nmake.exe in ManagedSinksWP\Interop Folder.

I am trying to create a sink which will create a copy of every email message that passes through the sink and saves it to a file on disk (say in a "c:\temp\").

Did any one have done something like this..if so help needed.

Thanks
prasad


June 25, 2004 1:49 AM
 

Mike said:

Nino: Thanks for your investigation. I got back to working on it today and finally reinstalled IIS and the SMTP service, once I did this and re-registered the event sink assembly, everything is working as advertised in article. So I can vouch that the article is still relevant and current. Thanks everyone for the input. - Mike
June 25, 2004 10:23 PM
 

nigelw said:

Pretish, you mentioned that you might be able to dig some information up? That is exactly what I need.

It would be really nice to get complete documentation on all of the interfaces declared in mailmsg.idl, smtpevent.idl and seo.idl. I've tried guessing functionality from the idl files, but you can only go so far with this.

Specific question is this: In a sink, how do I create new mailmsg objects to feed into the SMTP service? (I want to be able to split messages with multiple recipients into individual messages for per-user processing purposes).

Any help would be greatly appreciated. Thanks.
June 29, 2004 11:24 PM
 

NeedSmtpOutHelp said:


I would like to see some kind of clean sample that wires-up to specific SMTP codes when Exchange is the sender. For example, when Exchange SmtpSvc sends to a remote SMTP server and gets a 501, I would like to see that event trapped/handled in C#.

All of the samples out in the wild only deal with OnSmtpArrival.
July 12, 2004 7:22 PM
New Comments to this post are disabled

News

This is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified in the Terms of Use.

New! Would you like to suggest a topic for the Exchange team to blog about? Send suggestions to us.

Post Calendar

<June 2004>
SuMoTuWeThFrSa
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910