Sometime we need to trap all the outgoing/incoming email messages and would like to forward a copy of it to another recipient mailbox.
Here is sample script to achieve that:
Step 1: Install Exchange 2003 SDK on your Exchange Server. You can download it at the following link.
Step 2: Open Notepad and Paste the following code to it and save it as forward.vbs
NOTE: Following programming examples is for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This sample code assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures.
1: <SCRIPT LANGUAGE="VBScript">
3: Sub ISMTPOnArrival_OnArrival(ByVal Msg, EventStatus)
5: Dim RecpList
7: recplist = Msg.EnvelopeFields("http://schemas.microsoft.com/cdo/smtpenvelope/recipientlist")
9: 'Change "email@example.com" to the mailbox address to which you want to send a B’cc copy
10: If ( Instr(recplist,"SMTP:
firstname.lastname@example.org;") =< 0) then
11: recplist = recplist & "SMTP:
12: End If
13: Msg.EnvelopeFields("http://schemas.microsoft.com/cdo/smtpenvelope/recipientlist") = recplist
17: End Sub
19: Sub WriteLog(ByVal strMessage)
20: Dim fs
21: Set fs = CreateObject("Scripting.FileSystemObject")
22: Dim file
24: 'change "C:\bnewlog.txt" name/path of the log file
25: Set file = fs.opentextfile("C:\bnewlog.txt", 8, True)
26: file.Write strMessage
28: End Sub
Step 3: Register the event sink
1. Click Start -> Run, Type “cmd” and Click OK
2. Type “CD C:\Program Files\Exchange SDK\SDK\Support\CDO\Scripts” and Press Enter
3. Type cscript smtpreg.vbs /add 1 onarrival SMTPScriptingHost CDO.SS_SMTPOnArrivalSink “mail from=*” and Press Enter
4. Type cscript smtpreg.vbs /setprop 1 onarrival SMTPScriptingHost Sink ScriptName “C:\forward.vbs” and Press Enter (make sure that the path to forward.vbs is correct)
Now, all the incoming/outgoing emails bcc’ed/copied to email@example.com.
To unregister this event, type the following:
cscript smtpreg.vbs /remove 1 OnArrival SMTPScriptingHost
Please also refer to the following article 273233:You cannot modify MAPI messages that are trapped in an SMTP transport event sink.
Feel free to post your comments or request for messaging related development issues.