Platform SDK: SMTP Server Events

Protocol Event Sink Implementation Steps

[This is preliminary documentation and subject to change.]

Once you have completed the preliminary steps listed in the previous section, follow these steps to implement a protocol event sink:

  1. Implement a COM class that exposes the required interfaces:
    1. If you want your sink object to be cached from event to event, implement the SEO IEventIsCacheable interface. You simply return S_OK when the source calls IsCacheable method on your sink object.
    2. If you want your sink to receive the SinkProperties binding property bag from the dispatcher, implement the SEO IPersistPropertyBag interface. The event source checks first for the IEventIsCacheable interface, then the IPersistPropertyBag interface, and then notifies your sink of the event using the appropriate event interface listed below.
    3. The table below lists the interfaces required for each protocol event:
      Event Interface
      OnSmtpInboundCommand ISmtpInCommandSink
      OnSmtpOutboundCommand ISmtpOutCommandSink
      OnSmtpSessionStart ISmtpOutCommandSink
      OnSmtpMessageStart ISmtpOutCommandSink
      OnSmtpPerRecipient ISmtpOutCommandSink
      OnSmtpBeforeData ISmtpOutCommandSink
      OnSmtpSessionEnd ISmtpOutCommandSink
      OnSmtpServerResponse ISmtpServerResponseSink

      The sink will be created using the COM function CoCreateInstance. Therefore, your sink's class factory must expose the standard IClassFactory interface. No other creation mechanism is supported.

  2. Once you have completed implementing the necessary interfaces for the event, perform the following steps:
    1. Register the event sink COM class on the local machine. This registers the COM class identifier (CLSID) in the registry, and now the sink class can be created through the COM runtime method CoCreateInstance. This is how the event dispatcher will create and notify the event sink of the event occurrence.
    2. Register an event binding for the new sink using the SEO. This adds an entry for a particular SMTP service virtual instance, and specifies the COM class or programmatic identifier of the sink class, along with a simple display name. You will need to add the "rule" property to the binding SourceProperties property bag and optionally, a "priority" value. Additionally, you can add any number of additional properties to the binding SinkProperties property bag. These values are passed to your sink if it implements the SEO IPersistPropertyBag interface.
  3. Test your sink by creating some form of test program that connects to the service through a TCP/IP socket on port 25 and issues various commands. You may want to create a test harness using Perl, Java, or some other language to automate the testing process. Make sure to do bounds checking including inappropriate but "legal" orderings of protocol commands, sending malformed streams, etc. The SMTP service itself will perform basic verification during the dialog, but for certain commands, illegal byte or character sequences may be sent.