Platform SDK: Exchange 2000 Server |
[This is preliminary documentation and subject to change.]
The ISMTPOnArrival interface defines the interface between event sinks written with CDO and the SMTP service OnArrival event source.
Method
Name | Description |
---|---|
OnArrival | Called by the SMTP event source on bound OnArrival event sinks when a new message has arrived to the SMTP service. |
To implement an SMTP OnArrival event sink using CDO, you create and register a local COM class that provides an implementation of the CDO ISMTPOnArrival interface.
The passed CDO Message object is bound to an ADO Stream object containing the message contents within the SMTP transport. To commit any changes you make to the transport content, call IDataSource.Save. This does not affect the EnvelopeFields collection. Changes to the EnvelopeFields collection for the message are committed to the transport using the Fields.Update method for the collection.
The transport ADO Stream object is required to modify the message contents in the SMTP transport. If you want to bind the Message object to another object within your sink, using for example IDataSource.OpenObject or IDataSource.SaveToObject, make sure to first retrieve the transport Stream object reference using the Message object's IDataSource.Source property. If you do not, you will not be able to rebind the Message object to the transport Stream object and consequently you will not be able to update the message contents in the transport.
For more information on writing SMTP event sinks using CDO, see SMTP/NNTP Transport Event Sinks with CDO.
The code below is an example using the Active Template Library (ATL) to implement an SMTP OnArrival event sink.
#include "StdAfx.h" #include "sinkproj.h" // contains guids for this class #include "resource.h" #import "c:\program files\common files\system\ado\msado15.dll" raw_interfaces_only no_namespace #import "c:\exchsrvr\bin\cdoex.dll" raw_interfaces_only no_namespace class ATL_NO_VTABLE CMyClass : public CComObjectRootEx<CComSingleThreadModel>, public CComCoClass<CMyClass,&CLSID_MyClass>, public IDispatchImpl<ISMTPOnArrival,&__uuidof(ISMTPOnArrival),&LIBID_MyClass> { public: CMyClass() {} DECLARE_REGISTRY_RESOURCEID(IDR_MyClass) DECLARE_NOT_AGGREGATABLE(CMyClass) BEGIN_COM_MAP(CMyClass) COM_INTERFACE_ENTRY(ISMTPOnArrival) COM_INTERFACE_ENTRY(IDispatch) END_COM_MAP() // ISMTPOnArrival public: STDMETHOD(OnArrival) (/* in */ IMessage* pMsg, /* in,out */ CdoEventStatus* pEventStatus); private: // any other custom methods you wish to use }; CMyClass::OnArrival( IMessage* pMsg, CdoEventStatus* pEventStatus) { // TODO: add sink code here }
' Reference to ADO 2.5 and CDO for Microsoft Exchange Implements CDO.ISMTPOnArrival Private Sub ISMTPOnArrival_OnArrival( ByVal Msg As IMessage, pEventStatus as CdoEventStatus ) Msg.TextBody = Msg.TextBody & vbCrLf & "Text added by the sink." ' Commit the changes into the transport Stream Msg.DataSource.Save End Sub
<SCRIPT LANGUAGE="VBScript"> Sub ISMTPOnArrival_OnArrival( ByVal Msg, EventStatus ) Msg.TextBody = Msg.TextBody & vbCrLf & "Text added by the sink." ' Commit the changes into the transport Stream Msg.DataSource.Save End Sub </SCRIPT>