Writing Managed Sinks for SMTP and Transport Events

Published Jun 16 2004 02:36 PM 2,278 Views

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

12 Comments
%3CLINGO-SUB%20id%3D%22lingo-sub-610285%22%20slang%3D%22en-US%22%3EWriting%20Managed%20Sinks%20for%20SMTP%20and%20Transport%20Events%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-610285%22%20slang%3D%22en-US%22%3E%3CP%3E%3C%2FP%3E%3CP%3E%3CFONT%20face%3D%22Verdana%22%20size%3D%222%22%3ESummary%3A%20This%20document%20provides%20developers%20an%20overview%20of%20how%20to%20write%20event%20sinks%20for%20SMTP%20and%20Transport%20events%20in%20managed%20code%20using%20wrappers%20that%20obscure%20some%20of%20the%20details%20of%20communicating%20with%20the%20unmanaged%20server.%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20face%3D%22Verdana%22%20size%3D%222%22%3E%3CSTRONG%3EIntroduction%3C%2FSTRONG%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20face%3D%22Verdana%22%20size%3D%222%22%3EWriting%20event%20sinks%20in%20managed%20code%20allows%20the%20programmer%20to%20make%20use%20of%20the%20Microsoft%C2%AE%20.NET%20Framework%20and%20to%20more%20efficiently%20write%20the%20code%20that%20is%20necessary%20for%20the%20sink.%20Writing%20managed%20sinks%20can%20be%20somewhat%20difficult%2C%20however%2C%20because%20event%20sink%20interfaces%20were%20designed%20primarily%20for%20C%2B%2B%20programmers%20and%20are%20therefore%20not%20very%20easy%20to%20use%20in%20a%20language%20such%20as%20C%23.%20In%20addition%2C%20some%20of%20the%20methods%20that%20are%20imported%20using%20Tlbimp.exe%20will%20not%20work%20unless%20they%20are%20modified%20at%20the%20intermediate%20language%20(IL)%20level.%20However%2C%20these%20inconsistencies%20in%20the%20imported%20assemblies%20have%20been%20fixed%20in%20the%20events'%20primary%20interop%20assembly%20(PIA)%20provided%2C%20and%20other%20interfaces%20that%20were%20inconvenient%20to%20use%20have%20also%20been%20wrapped%20so%20that%20they%20are%20easier%20to%20use%20from%20managed%20code.%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20face%3D%22Verdana%22%20size%3D%222%22%3EThese%20managed%20wrappers%20wrap%20each%20of%20the%20methods%20on%20the%20original%20interfaces%20and%20correctly%20communicate%20with%20the%20unmanaged%20server.%20In%20addition%2C%20some%20of%20the%20original%20methods%20are%20exposed%20as%20properties%20instead%20of%20pairs%20of%20methods.%20For%20example%2C%20all%20pairs%20of%20Set%20and%20Query%20methods%20are%20exposed%20as%20properties.%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20face%3D%22Verdana%22%20size%3D%222%22%3EThis%20document%20assumes%20that%20the%20reader%20has%20a%20working%20knowledge%20of%20the%20.NET%20Framework%2C%20COM%2C%20COM%20Interop%20and%20Microsoft%20Windows%C2%AE%202000%20SMTP%20Service%20Events.%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20face%3D%22Verdana%22%20size%3D%222%22%3EFor%20information%20about%20event%20sinks%20in%20general%2C%20see%20%3CA%20href%3D%22http%3A%2F%2Fmsdn.microsoft.com%2Flibrary%2Fdefault.asp%3Furl%3D%2Flibrary%2Fen-us%2Fdnsmtps%2Fhtml%2Ftransportevents.asp%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EMicrosoft%20Windows%202000%20SMTP%20Service%20Events%3C%2FA%3E.%20As%20described%20in%20that%20document%2C%20sinks%20can%20implement%20a%20number%20of%20interfaces%20to%20handle%20corresponding%20events%20on%20the%20server.%20The%20methods%20of%20those%20interfaces%20are%20then%20called%20when%20the%20appropriate%20event%20is%20triggered%20and%20certain%20parameters%20are%20passed%20in.%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20face%3D%22Verdana%22%20size%3D%222%22%3E%3CSTRONG%3EHow%20to%20Write%20a%20Managed%20Event%20Sink%20in%20C%23%3A%20Step%20by%20Step%3C%2FSTRONG%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20face%3D%22Verdana%22%20size%3D%222%22%3ETo%20write%20a%20managed%20event%20sink%2C%20you%20must%20link%20to%20the%20PIA%20that%20contains%20the%20necessary%20interfaces%20and%20implement%20the%20interfaces%20that%20correspond%20to%20the%20events%20that%20need%20to%20be%20handled.%20Optionally%2C%20you%20can%20link%20to%20the%20assembly%20that%20contains%20the%20easier-to-use%20wrappers%20for%20these%20interfaces.%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20face%3D%22Verdana%22%20size%3D%222%22%3E%3CA%20href%3D%22http%3A%2F%2Fmsdn.microsoft.com%2Flibrary%2Fdefault.asp%3Furl%3D%2Flibrary%2Fen-us%2Fdnsmtps%2Fhtml%2Fwritingmngsinks.asp%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3ERead%20the%20rest%20on%20MSDN%20web%20site...%3C%2FA%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20face%3D%22Tahoma%22%20size%3D%222%22%3E%3CA%20href%3D%22http%3A%2F%2Fblogs.msdn.com%2Fexchange%2Farticles%2F94842.aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EPretish%20Abraham%3C%2FA%3E%3C%2FFONT%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-610285%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAll%20Posts%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EDevelopment%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EDocumentation%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Version history
Last update:
‎Jul 01 2019 02:57 PM
Updated by:
We support Ukraine and condemn war. Push Russian government to act against war. Be brave, vocal and show your support to Ukraine. Follow the latest news HERE