Platform SDK: CDO for Windows 2000

Changing the Message Content

The Message object passed to an event sink is pre-bound to an ADO Stream object that contains the message content in the SMTP transport. The IDataSource.SourceClass property on the Message object returns the string "_Stream". When you make changes to the message content from within the sink, the changes are not committed to the transport until you call the IDataSource.Save method.

If you want to rebind the Message object to another object, make sure to cache the reference to the ADO Stream object in the transport using the IDataSource.Source property. If you rebind the Message object without caching this reference, you will not be able to rebind the Message object to the transport stream.

[Visual Basic]
' Reference to Microsoft ActiveX Data Objects 2.5 Library
' Reference to Microsoft CDO for Windows 2000 Library

Implements CDO.ISMTPOnArrival
Implements IEventIsCacheable

Private Sub IEventIsCacheable_IsCacheable()
 ' just returns S_OK
End Sub

Private Sub ISMTPOnArrival_OnArrival(ByVal Msg As CDO.Message, EventStatus As CDO.CdoEventStatus)
  iMsg.TextBody = iMsg.TextBody & _
    vbCrLf & _
    "-- This was added to the message from within an event sink" & _
    vbCrLf

  ' Commit the content changes to the transport ADO Stream object
  iMsg.DataSource.Save
  EventStatus = cdoRunNextSink
End Sub
[VBScript]
<SCRIPT LANGUAGE="VBScript">

Const cdoRunNextSink = 0
Const cdoSkipRemainingSinks = 1

Sub IEventIsCacheable_IsCacheable()
 ' just returns S_OK
End Sub

Sub ISMTPOnArrival_OnArrival(ByVal Msg, EventStatus)
  iMsg.TextBody = iMsg.TextBody & _
    vbCrLf & _
    "-- This was added to the message from within an event sink" & _
    vbCrLf
  
  ' Commit the content changes to the transport ADO Stream object
  iMsg.DataSource.Save
  EventStatus = cdoRunNextSink
End Sub
</SCRIPT>

See Also

IDataSource.Save Method

ADO Stream Object

IDataSource.Source Property

IDataSource.SourceClass Property