How to use Win2000 Server CDOSYS Event Sink to Process e-Mails
It is possible to register a DLL or VBScript to the Windows 2000 SMTP Event Sink, such that when E-mails arrives, or posted, will trigger the DLL or the VBScript to do certain process like Spam Block or E-Mail Redirect.
To accomplish this, we will need to download a vbscript called smtpreg.vbs from the Windows 2003 Platform 2003. The purpose of this this smtpreg.vbs is to register and to unregister the DLL’s and the VBScripts on certain events like "onarrival", "onpost" etc.
For example, if you have a DLL used to log the incoming e-mail. The registered PROGID of this DLL is called CDOTest.Class1. Now, to register this DLL to the Windows 2000 CDOSYS, type the command line:
cscript smtpreg /add 1 onarrival CDOTest.Class1 "mail from=*"
This means, on all the incoming e-mails (mail from=*), please call the class in a DLL who is registered to the registry as CDOTest.Class1.
The VB source code of this DLL is like:
Implements CDO.ISMTPOnArrival
Implements IEventIsCacheable
Private Sub IEventIsCacheable_IsCacheable()
’ just returns S_OK
End Sub
Private Sub ISMTPOnArrival_OnArrival(ByVal Msg As CDO.Message, EventStatus As CDO.CdoEventStatus)
Dim fs As New Scripting.FileSystemObject
Dim file As Scripting.TextStream
Set file = fs.OpenTextFile("c:\yamabay\test.log", ForAppending, True)
file.Write "From: " & Msg.From & vbCrLf
file.Write "To: " & Msg.To & vbCrLf
file.Write "Subject: " & Msg.Subject & vbCrLf & vbCrLf
file.Write Msg.TextBody & vbCrLf & vbCrLf
file.Close
EventStatus = cdoRunNextSink
End Sub
After you have made the DLL, registered it, and type the smtpreg.vbs command, the incoming mails will be recorded in c:\yamabay\test.log.
Click here to find the VB Project and smtpreg.vbs

0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home