End Sub
' just returns S_OK and makes SINK faster
Set objFields = Msg.EnvelopeFields
strInput = objFields (RECIPIENTS).Value If DebugIt ThenEnd If If Len (strInput) > 0 Then
objShell.LogEvent EVENT_SUCCESS, "Event sink input: '" & strInput & "'"
strOutput = AssembleRecipientList (strInput)
objFields (RECIPIENTS).Value = strOutput
objFields.Update
Msg.DataSource.Save
End If If DebugIt Then
objShell.LogEvent EVENT_SUCCESS, "Event sink output: '" & strOutput & "' time = " & (Timer - StartTime)
End If Call DoUnInit ()
objShell.LogEvent EVENT_SUCCESS, "LDAP Query String: '" & strQuery & "'"End If Com.ActiveConnection = Conn
End If ' Iterate through the results.
objShell.LogEvent EVENT_ERROR, "Com.Execute " & Err.Number & " " & Err.Description
SearchForAddress = False
Exit Function
Wend ' Done with this LDAP query
Rs.Close
Exit Function
' Can't log an error - don't have any way to!End If Err.Clear
DoInit = False
Set oRootDSE = Nothing
Exit Function
objShell.LogEvent EVENT_ERROR, "Conn.Create " & Err.Number & " " & Err.DescriptionEnd If Err.Clear
DoInit = False
Set oRootDSE = Nothing
Set objShell = Nothing
Exit Function
objShell.LogEvent EVENT_ERROR, "Com.Create " & Err.Number & " " & Err.DescriptionEnd If ' Open the connection.
DoInit = False
Set oRootDSE = Nothing
Set objShell = Nothing
Set Conn = Nothing
Exit Function
objShell.LogEvent EVENT_ERROR, "Conn.Open " & Err.Number & " " & Err.DescriptionEnd If End Function Sub DoUnInit ()
DoInit = False
Set oRootDSE = Nothing
Set objShell = Nothing
Set Conn = Nothing
Set Com = Nothing
Exit Function
End Sub '
Conn.Close
Set objShell = Nothing
Set Com = Nothing
Set Conn = Nothing
Set Rs = Nothing
Set oRootDSE = Nothing
Loop While lenTemp > 0
i = InStr (strTemp, ";")
If i = 0 Then
' no more semi-colons, we are at the end of the list
strL = strTemp
lenL = Len (strL)
strTemp = ""
lenTemp = 0
Else
strL = Left (strTemp, i)
lenL = i
strTemp = Right (strTemp, Len (strTemp) - i)
lenTemp = Len (strTemp)
End If If lenL > 0 ThenEnd If
If (InStr (strL, strYourDomain1) = 0) And (InStr (strL, strYourDomain2) = 0) And (InStr (strL, strYourDomain3) = 0) And (InStr (strL, strYourDomain4) = 0) And (InStr (strL, strYourDomain5) = 0) Then
' this address does not contain the email domain of interestElse
strEmailList = strEmailList & strLEnd If
If i > 0 Then
FoundIt = SearchForAddress (Left (strL, lenL - 1)) ' strip terminal ";"Else
FoundIt = SearchForAddress (strL)End If If Not FoundIt ThenElse
' address entry not found, so point to catchall address
strEmailList = strEmailList & strDestinationEmail
' address entry was found, don't change itEnd If
strEmailList = strEmailList & strL
Register the event sink:
To register your event sink, use the Smtpreg.vbs file, which is installed with the Exchange SDK. From a command prompt, browse to the ...Exchange SDKSDKSupportCDOScripts folder and type the following (make sure that the path to EventSinkScript.vbs is correct):
cscript smtpreg.vbs /add 1 onarrival SMTPScriptingHost CDO.SS_SMTPOnArrivalSink "mail from=*"
cscript smtpreg.vbs /setprop 1 onarrival SMTPScriptingHost Sink ScriptName "C:EventSinkScript.vbs"
If the command succeeds, you receive a success message generated by the script.
To unregister this event, type the following:
cscript smtpreg.vbs /remove 1 OnArrival SMTPScriptingHost
Note If you use a MAPI client such as Microsoft Outlook to send the e-mail, the recipient does not receive a modified message. This is because messages submitted using MAPI are not in SMTP format when the e-mail triggers the SMTP transport event. Therefore, changes that are made by the event's code are not persisted.