Dela via


ISMTPOnArrival Interface

Topic Last Modified: 2006-06-13

The ISMTPOnArrival interface defines the interface between event sinks written with Collaboration Data Objects (CDO) and the SMTP service OnArrival event source.

CLSID

CD000026-8B95-11D1-82DB-00C04FB1625D

Extends

IDispatch

Type Library

Microsoft CDO for Exchange 2000 Library

DLL Implemented In

CDOEX.DLL

Member Summary

The following table lists the methods of the ISMTPOnArrival interface.

Name Description

OnArrival

Called by the SMTP event source on bound OnArrival event sinks when a new message has arrived to the SMTP service.

Remarks

To implement an SMTP OnArrival event sink using CDO, you create and register a local Component Object Model (COM) class that provides an implementation of the CDO ISMTPOnArrival interface.

The passed CDO Message object is bound to a Microsoft® ActiveX® Data Objects (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 about writing SMTP event sinks using CDO, see SMTP/NNTP Transport Event Sinks with CDO.

Examples

[C++,IDL]

The following code uses 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:\program files\common files\microsoft shared\cdo\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
}

[Visual Basic]

' 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

[VBScript]

<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>

See Also

Other Resources

SMTP/NNTP Transport Event Sinks with CDO