Monday, July 18, 2005

Use Win2000 Server CDOSYS Event Sink to Process e-Mails: C# and VB.NET ways

CDOSYS is COM based. It may become part of the .NET Framework in the future version of Windows. At this point, if we want to develop CDOSYS Event Sink by using C# or VB.NET, we will need to add .NET Wrappers to the CDOSYS COM object, to let the .NET world access CDOSYS.

Before we start to do this, we will need to download some code from Microsoft. Please click here to download.

Once we download the code and extracted them into, say, c:\ManagedSinkWP, we can start to do the followings:

To build the interop

From a command prompt, run \Program Files\Microsoft Visual Studio .NET\Common7\Tools\vsvars32.bat.
Run nmake.exe from the directory of the interop (\ManagedSinksWP\Interop).
To build the wrappers

Copy the interop DLL (Microsoft.Exchange.Transport.EventInterop.dll) to the wrappers directory (\ManagedSinksWP\Wrappers).
In the same environment as the interop, run the following from the wrappers directory:
Note The following code has a carriage return inserted for readability. When implementing this code, do not include the carriage return.

csc /t:library /out:Microsoft.Exchange.Transport.EventWrappers.dll /r:Microsoft.Exchange.Transport.EventInterop.dll *.cs /unsafe
To write the event sink

Click here to get the working sample project I provided.

Now, assume we have already built the COM called ManagedSinks.ShieldsUp from my sample code , then you can do (from command line):

cscript smtpreg.vbs /add 1 OnInboundCommand "Sample managed sink" ManagedSinks.ShieldsUp EHLO
This will send a reject message to the sender if EHLO command is received.
You can test this by doing (from command line):
telnet localhost 25
EHLO
To uninstall the Event Sink, you can do:
cscript smtpreg.vbs /remove 1 OnInboundCommand "Sample managed sink"
For detailed information, please go to:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsmtps/html/writingmngsinks.asp?frame=true#writingmngsinks_topic2

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home