Platform SDK: CDO for Windows 2000

Sink Example Using VBScript

The following sink example is written in VBScript. To use this example, register the CDO Simple Mail Transfer Protocol (SMTP) OnArrival event scripting host (CDO.SS_SMTPOnArrivalSink) and then configure the ScriptName property in the binding's Sink property bag to point to the file containing the script below. For more information, see Implementing Sinks with Scripting Languages and Registering Script Sink Bindings.

<SCRIPT LANGUAGE="VBScript">
Sub ISMTPOnArrival_OnArrival(ByVal Msg, EventStatus )

  Dim fs
  Set fs = CreateObject("Scripting.FileSystemObject")
  Dim file
  Set file = fs.OpenTextFile("e:\script\test.log", 8, 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
</SCRIPT>

The registration script will resemble the following example:

cscript smtpreg.vbs /add     1 onarrival SMTPScriptingHost CDO.SS_SMTPOnArrivalSink "mail from=*"
cscript smtpreg.vbs /setprop 1 onarrival SMTPScriptingHost Sink ScriptName "c:\path\to\sinkscript.vbs"