Microsoft KB Archive/317680

= How to add a disclaimer to outgoing SMTP messages in Visual Basic script =

Article ID: 317680

Article Last Modified on 10/25/2007

-

APPLIES TO


 * Microsoft Exchange Server 2003 Enterprise Edition
 * Microsoft Exchange Server 2003 Standard Edition
 * Microsoft Exchange 2000 Server Standard Edition
 * Collaboration Data Objects for Exchange 2000
 * Microsoft Collaboration Data Objects 2.0

-



This article was previously published under Q317680





For a Microsoft Visual Basic version of this article, see 317327.



SUMMARY
This step-by-step article shows how to use an SMTP transport event sink to add a disclaimer to outgoing SMTP e-mail messages.

Create the event sink
To create an event sink, paste the following code in a new file and save it as EventSinkScript.vbs.  Sub ISMTPOnArrival_OnArrival(ByVal Msg, EventStatus) TextDisclaimer = vbCrLf & &quot;DISCLAIMER:&quot; & vbCrLf & &quot;Sample Disclaimer added in a VBScript.&quot; HTMLDisclaimer = &quot;  DISCLAIMER: Sample Disclaimer added in a VBScript.&quot;

If Msg.HTMLBody <> &quot;&quot; Then 'Search for the &quot; &quot; tag and insert our disclaimer before that tag. pos = InStr(1, Msg.HTMLBody, &quot; &quot;, vbTextCompare) szPartI = Left(Msg.HTMLBody, pos - 1) szPartII = Right(Msg.HTMLBody, Len(Msg.HTMLBody) - (pos - 1)) Msg.HTMLBody = szPartI + HTMLDisclaimer + szPartII End If

If Msg.TextBody <> &quot;&quot; Then Msg.TextBody = Msg.TextBody & vbCrLf & TextDisclaimer & vbCrLf End If  'Commit the content changes to the transport ADO Stream object. Msg.DataSource.Save ' Commit the changes into the transport Stream

EventStatus = cdoRunNextSink End Sub 

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 SDK\SDK\Support\CDO\Scripts 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 &quot;mail from=*@your-domain-here.com&quot;

cscript smtpreg.vbs /setprop 1 onarrival SMTPScriptingHost Sink ScriptName &quot;C:\EventSinkScript.vbs&quot;

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

For more information on registering events with Smtpreg.vbs, see the &quot;Managing Event Bindings&quot; topic on the following MSDN Web site:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cdosys/html/7406817f-b48f-4b62-86af-bd6703fca4f6.asp

For more information, click the following article number to view the article in the Microsoft Knowledge Base:

324021 How to create a &quot;catchall&quot; mailbox sink for Exchange Server

Test the event sink
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 and if the Exchange mailbox resides on the same server as the event sink binding, the recipient may not receive the modified message. This is because messages that are submitted by 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.

