Create the event sink TextDisclaimer = vbCrLf & "DISCLAIMER:" & vbCrLf & "Sample Disclaimer added in a VBScript." If Msg.HTMLBody <> "" Then 'Search for the "</body>" tag and insert our discliamer before that tag. If Msg.TextBody <> "" Then Msg.TextBody = Msg.TextBody & vbCrLf & TextDisclaimer & vbCrLf 'Commit the content changes to the transport ADO Stream object. 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): 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 To test your sink, send an e-mail message to an SMTP recipient who is external to your organization. The recipient should receive a modified message with the disclaimer added to the end of the message. 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.
To create an event sink, paste the following code in a new file and save it as EventSinkScript.vbs: <SCRIPT LANGUAGE="VBScript">
Sub ISMTPOnArrival_OnArrival(ByVal Msg, EventStatus)
HTMLDisclaimer = "<p></p><p>DISCLAIMER:<br>Sample Disclaimer added in a VBScript."
pos = InStr(1, Msg.HTMLBody, "</body>", vbTextCompare)
szPartI = Left(Msg.HTMLBody, pos - 1)
szPartII = Right(Msg.HTMLBody, Len(Msg.HTMLBody) - (pos - 1))
Msg.HTMLBody = szPartI + HTMLDisclaimer + szPartII
End If
End If
Msg.DataSource.Save
' Commit the changes into the transport Stream
pEventStatus = cdoRunNextSink
</SCRIPT>
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=*@your-domain-here.com"
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.
Test 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): If the command succeeds, you receive a success message generated by the script.