The Event Dispatcher and Event Notification
An event dispatcher thread is the source of transport events. For each type of transport event that occurs, such as the arrival of a message to the Simple Mail Transfer Protocol (SMTP) service or the arrival of headers to the Network News Transfer Protocol (NNTP) service, the event-binding database is checked for applicable sink bindings. Once the bindings are identified, the event dispatcher thread notifies each sink of the event in the sequence defined by the binding priorities. The following diagram outlines this process.
Each sink is run in the order defined by the binding Priority value. Sinks with the lowest priority run first. For each sink, the following process occurs:
- The source compares the sink's binding Rule condition with the transmitted protocol commands (or equivalent x-headers, such as x-receiver in the case of the pickup directory). If the condition is not met, the sink is skipped. If the condition is met, the sink is executed.
- If necessary, the source creates an instance of the sink Component Object Model (COM) class using the programmatic identifier or COM class identifier (CLSID) that is identified in the binding. If a cached instance of the sink exists, it is used and a new instance is not created.
- The source calls the IUnknown::QueryInterface method on the newly created object to get the appropriate interface. For the SMTP OnArrival event, this interface is ISMTPOnArrival. For NNTP events, this interface is INNTPOnPostEarly, INNTPOnPost, or INNTPOnPostFinal.
- The source executes the sink by calling the appropriate event method on the event interface, such as ISMTPOnArrival.OnArrival. The IMessage interface on a Microsoft® Collaboration Data Objects (CDO) Message object is passed as the first argument to the method. For the SMTP OnArrival, NNTP OnPost, and NNTP OnPostFinal events, this object contains the message in its entirety along with the transport envelope fields. For the NNTP OnPostEarly event, the message contains the headers and transport envelope fields only. The passed Message object is bound to an ADO Stream object containing the message content within the associated transport. The IMessage.EnvelopeFields property, which is exposed on the Message object, provides access to the transport envelope fields for the message. This is the only time that the IMessage.EnvelopeFields property is populated in a Message object. For NNTP events, the content is read-only and therefore cannot be altered. For the SMTP event, the content is read-write and can be modified by the sink.
- Once the sink finishes running, the dispatcher thread checks the event status flag returned by the sink to determine whether to notify subsequent sinks. If the sink returns cdoRunNextSink for the event status, it notifies the next sink. If the sink returns cdoSkipRemainingSinks, no further sinks are notified of the event.
After each sink has been notified, or after one of the sinks indicates to skip the remaining sinks, the appropriate status envelope field is examined for the message (either messagestatus for the SMTP OnArrival event, or nntpprocessing for the NNTP OnPostEarly and OnPost events). For OnPostFinal events, the message has already been posted and the sink cannot alter the status of the message. Appropriate action is then taken based on that value. For SMTP messages, the message is delivered to the appropriate location (drop directory or the Exchange store, if applicable), discarded, or placed in the bad-mail location. For NNTP messages, the appropriate processing is carried out: post, process, moderate. Any combination can be indicated. If the sink does not indicate one of post, process, or moderate, the message is discarded and is not posted.
See Also
messagestatus Field
nntpprocessing Field
IMessage.EnvelopeFields Property
CdoEventStatus Enumeration