Become a Columnist Microsoft Exchange Site Microsoft Support SiteMSDN Exchange Site

   

Subscribe to OutlookExchange
Anderson Patricio
Ann Mc Donough
Bob Spurzem
Brian Veal
Catherine Creary
Cherry Beado
Colin Janssen
Collins Timothy Mutesaria
Drew Nicholson
Fred Volking
Glen Scales
Goran Husman
Guy Thomas
Henrik Walther
Jason Sherry
Jayme Bowers
John Young
Joyce Tang
Justin Braun
Konstantin Zheludev
Kristina Waters
Kuang Zhang
Mahmoud Magdy
Martin Tuip
Michael Dong
Michele Deo
Mitch Tulloch
Nicolas Blank
Pavel Nagaev
Ragnar Harper
Ricardo Silva
Richard Wakeman
Russ Iuliano
Santhosh Hanumanthappa
Steve Bryant
Steve Craig
Todd Walker
Tracey J. Rosenblath
 
 

SMTP Switch / Journal per Domain

Introduction

In a Recent Microsoft Qbase article it shows how you can capture all emails sent to a particular SMTP domain and redirect them to a certain mailbox check out this Qbase article for more details. This has been possible in products such as Qmail and versions of Sendmail for sometime by allowing delivery to *.domain . What I've done in this article is take the same basic idea but instead apply it in a different way to create a SMTP switch example which allows you to have users on different email platforms such as Notes and Exchange receive inbound email for the same SMTP domain name. Also another script using the same idea that will allow you to do message journaling based on certain SMTP domains or users.

How it works

This script uses SMTP Transport event Sinks that are part of the Windows 2000 SMTP server. Before using these scripts it would be wise to understand how transport sinks work in W2k and what the limitations and affect running these type of scripts will have on your SMTP server. First by default the SMTP server on W2k works asynchronously which means that it can accept and process multiple incoming and outgoing mails in a parallel nature. A transport event happens after the mail message has been received by the SMTP server (after the protocol conversations have happened and have been written to the SMTP log file if you have logging enabled). There are several types of transport sinks you can use the one that is used in this article is the CDO_OnArrival event sink which is an event sink wrapper for the OnSubmission Event. This allows you to write the transport sink in higher level languages such as VBS and VB. The disadvantage of this is if you implement sinks using the CDO_OnArrival event your SMTP server will now work in a synchronous or serial manner which is going to limit the performance and scalability of your SMTP server. To be able to keep the asynchronously nature of  the SMTP server you would need to implement your event sinks in C++ using the OnSubmission Event Sink please have a read of this Microsoft article for more details.

Envelope fields

When a message is sent via SMTP the message itself is enclosed in a logical envelope that gets passed from one SMTP server to another. The actual Too field on a message in only read by the originating server when the original message is encoded for transfer. The Envelope fields contains the recipient list which is used by the SMTP servers as the mail is relayed from one to another to determine if the mail is for a local mailbox on that server or if it should be retransmitted to another server for delivery. As the email gets accepted for delivery by SMTP servers the recpientlist is altered as the mail is delivered locally or retransmitted if necessary to deliver to all recipients. For a Technically correct explanation of this take a look at RFC 821 and RFC 822 which is a recommended read that will help you if you have every tried to decode any SMTP log files.

Caveats using the Envelope fields

There are a few caveats when using envelope fields with Exchange 2000 the first is if you are sending a mail from a mailbox that exist on the same SMTP server where the event sink is the senderemailaddress field of the message will be blank so if you are firing your sink on a Mail from=* rule the sink wont fire for any mail sent from this server. This can be usefully if you only want to fire the sink on mail received from another server. If you want to fire it on all outgoing mail as well as incoming you need to use the Rcp To=* rule. Its a good idea to have a read of this Qbase article so you can understand issues you may experience with MAPI messages and transport events.

Warning: It can be quite easy to make a logic error when you are playing around with the smtpenvelope fields which could create an endless message loop on your SMTP server so before you use any of these scripts make sure you test then in a lab enviroment.

SMTP Switch Example    Journal per domain example


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