Home  |  Services  |  About Us  |  Contact  | 


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:
  1. If the sender is joe@shmo.com and the recipient is InternalUser1@YourCompany.com, then allow the message through unimpeded.
  2. 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.
The steps:
  1. 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.)
  2. 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.)
  3. 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.)
  4. Edit EventSinkScript.vbs using any text editor.  Modify the values of InternalUser1@YourCompany.com and InternalUser2@YourCompany.com.
  5. 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"
  6. 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.
  7. 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.
  8. 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.