![]() |
|
|
| Become a Columnist Microsoft Exchange Site Microsoft Support SiteMSDN Exchange Site | ||
|
|
SMTP Switch Example Download ScriptIf you've ever done a mail migration or have any legacy email systems operating in your network you may have come across the need to be able to receive email for a certain SMTP domain by multiple back end systems such as a Unix sendmail server or a lotus Notes server. There are some commercial products available that let you do this such as sendmail switch and for a mail system that has a large volume of messages or for a long term solution these products will probably serve you better. However for a lot of mail migrations there is only a need to do this for a short period of time or ongoing on for a low volume legacy system so this script offers a low cost SMTP switch solution that can be implemented on any Windows 2000 SMTP server How it worksTo explain this I'll use a example of a typical migration scenario, Within the SMTP_Onarrival event you can access the Msg object which is a CDO handle to the message being processed by the SMTP server. The Msg.EnvelopeFields("http://schemas.microsoft.com/cdo/smtpenvelope/recipientlist") field contains the list of recipients of a message before it is processed by the categorizer. (The Categorizer is responsible for determining mail delivery). What the below script does is it goes though the recipient list and using the VB replace command replaces the email address's of your notes users with the secondary email address's you created above. When the message hits the categorizer it will see that the message needs to be sent to the note server (using the MX record you created for the sub domain) and will retransmit the message with the SMTP envelope field addressed to the secondary address you created. The notes server will receive it and deliver it to the user, the user will get their email as normal addressed to their primary account (remember the actually To field of the message isn't used for delivery of the message the recipient list in the envelope field is which is the one we have modified ref rfc821) Using this scriptThere are two options for using this script you can fire the script on all mail sent to or from any users using a rule such as mail from=* or Rcpt To=* and then place a replace command for all the users you have on your target system (the notes system in my example) so your script would look like this <SCRIPT LANGUAGE="VBScript">
Sub ISMTPOnArrival_OnArrival(ByVal Msg, EventStatus )
recplist = LCase(Msg.EnvelopeFields("http://schemas.microsoft.com/cdo/smtpenvelope/recipientlist"))
rem User Replace Statements use lower case
recplist = replace(recplist, "SMTP:user1@yourdomain.com", "SMTP:user1@mailmig.yourdomain.com")
recplist = replace(recplist, "SMTP:user2@yourdomain.com", "SMTP:user2@mailmig.yourdomain.com")
recplist = replace(recplist, "SMTP:user3@yourdomain.com", "SMTP:user3@mailmig.yourdomain.com")
rem End User Replace Statement
Msg.EnvelopeFields("http://schemas.microsoft.com/cdo/smtpenvelope/recipientlist") = recplist
Msg.EnvelopeFields.update
EventStatus = cdoRunNextSink
End Sub
</SCRIPT>
The other option is to create a separate script for each user you have on your legacy system and then create one sink for each user that fires on mail sent to their email address eg: Rcpt To=youruser@yourdomain.com. This has the advantage that the script will only run on mail sent to that user and not on all email that goes through the server, this should have a better impact on performance and is a good option when you may only have a few databases on your Notes server that you want to keep receiving email. But even when you have a large number of users on the other server seperate sinks can still give you better performance because you are avoiding the overhead of firing the VB script on ever email.
<SCRIPT LANGUAGE="VBScript">
Sub ISMTPOnArrival_OnArrival(ByVal Msg, EventStatus )
recplist = LCase(Msg.EnvelopeFields("http://schemas.microsoft.com/cdo/smtpenvelope/recipientlist"))
rem User Replace Statements use lower case
recplist = replace(recplist, "SMTP:user1@yourdomain.com", "SMTP:user1@mailmig.yourdomain.com")
rem End User Replace Statement
Msg.EnvelopeFields("http://schemas.microsoft.com/cdo/smtpenvelope/recipientlist") = recplist
Msg.EnvelopeFields.update
EventStatus = cdoRunNextSink
End Sub
</SCRIPT>
Installation Before using this script you need to put in your own domain variables to replace the yourdomain.com text in the script. To install and use an SMTP event sink you will first require the SMTPREG.vbs script that is included in the Exchange SDK. Create a directory on your servers c: drive called c:\smtpevt and copy the smtpreg.vbs and smtpswit.vbs scripts into this directory. To create an event sink for the smtpswit.vbs script that will fire when mail arrives from * . From a command line in the c:\smtpevt directory type cscript smtpreg.vbs /add 1 onarrival smtpswitch CDO.SS_SMTPOnArrivalSink "Mail from=*" You then need to associate the smtpevt.vbs script to this event sink you have created using cscript smtpreg.vbs /setprop 1 onarrival smtpswitch Sink ScriptName c:\smtpevt\smtswit.vbs Once this has been done you need to stop and start the SMTP service and your event sink will now be active. If you wish to delete this event sink latter type cscript smtpreg.vbs /remove 1 onarrival smtpswitch
|
Disclaimer: Your use of the information contained in these pages is at your sole risk. All information on these pages is provided "as is", without any warranty, whether express or implied, of its accuracy, completeness, fitness for a particular purpose, title or non-infringement, and none of the third-party products or information mentioned in the work are authored, recommended, supported or guaranteed by Stephen Bryant or Pro Exchange. OutlookExchange.Com, Stephen Bryant and Pro Exchange shall not be liable for any damages you may sustain by using this information, whether direct, indirect, special, incidental or consequential, even if it has been advised of the possibility of such damages.
Copyright Stephen Bryant 2008