
Main Menu
Brad's TechTips - Exchange Server & Outlook
[<<
Full list of Exchange Server & Outlook tips.]
Exchange Server 2003: Create an Event Sink to Change The Recipient Address Based on Sender and Recipient
Here's a method that will allow Exchange Server to analyze incoming email and modify the recipient using the following logic:
Exchange Server 2003: Create an Event Sink to Change The Recipient Address Based on Sender and Recipient
Here's a method that will allow Exchange Server to analyze incoming email and modify the recipient using the following logic:
- If the sender is joe@shmo.com and the recipient is InternalUser1@YourCompany.com, then
allow the message through unimpeded.
- If the sender is joe@shmo.com but the recipient is any other user at YourCompany.com, then redirect (forward, not copy) the message to InternalUser2@YourCompany.com.
- Create a folder at c:\temp on your Exchange Server. (You can
actually use any directory, but the scripts below reference c:\temp.
Make changes accordingly.)
- Download the SMTPReg.txt file into c:\temp and then rename it as
SMTPReg.vbs. (This script is also available in the Microsoft Exchange
Server 2000
SDK.)
- Download
EventSinkScript.txt into c:\temp and then rename it as
EventSinkScript.vbs. (Note: the
file may appear empty if you just click the hyperlink to open it in your
browser. This is due to the nature of the code inside the file.)
- Edit EventSinkScript.vbs using any text editor. Modify
the values of InternalUser1@YourCompany.com and
InternalUser2@YourCompany.com.
- Register the event sink by running the following lines in succession
from a command prompt. Each command should be on a single line and not
word-wrapped as it appears in this browser window.
(Note that the number 1 that appears in each line refers to the instance of the SMTP virtual server to which this sink will be applied. In most cases, you will have just one virtual server, so you can leave it as is. If you have more than one SMTP virtual server on your Exchange server, then modify the value as needed.)
cscript "c:\temp\smtpreg.vbs" /add 1 onarrival EventSinkScript.vbs CDO.SS_SMTPOnArrivalSink "mail from=joe@shmo.com"
cscript "c:\temp\smtpreg.vbs" /setprop 1 onarrival EventSinkScript.vbs Sink ScriptName "c:\temp\eventsinkscript.vbs"
- Test the script's functionality by running the first line in the
previous step using an external, test account rather than the "real"
joe@shmo.com account. In other words, replace joe@shmo.com
with your external Gmail, Hotmail or other account. Then
send a message to InternalUser1@YourCompany.com from that personal
account. It should pass unimpeded. Send a second message to
another account in your organization; it should be auto-forwarded to
InternalUser2@YourCompany.com.
- If you are satisfied with the testing results, then rerun the first
cscript line, but this time using the real email address of the
sender whose messages you want to
filter.
- If you find that things aren't going your way, you can unregister the
event sink by running the following line in a command prompt:
cscript "c:\temp\smtpreg.vbs" /remove 1 OnArrival EventSinkScript.vbs
* Special thanks to James Chong, Microsoft MVP (Exchange Server) for his assistance in troubleshooting the script.