|
Summary
Set message body or attachments.
Description
The OnSetBody event occurs in response to calling the CreateMessage method. During the
create message process, the OnSetBody event will be fired to obtain the body of the
message, as well as any attachments.
The MIME ActiveX control will fire the OnSetBody event first to obtain the body of the
message. Assign the message body to Buffer and set the IsFile parameter to
0, or if the body is in a file you should assign the filename to Buffer and set the
IsFile parameter to 1. The Length parameter should be set to the length of Buffer.
Once the MIME control builds the main header and body of the message, it will fire the
OnSetHeader and OnSetBody events to obtain information for the attachments.
Attachments can be sent by setting the Buffer parameter to the complete path and
name of the file and the IsFile parameter to 1, or by setting the Buffer
parameter to the contents of the attachment and the IsFile parameter to 0. In both
cases the Length parameter should be set to the length of the buffer string.
In the case where the actual contents of the message body or attachment are being
passed in this event, the MIME ActiveX control will keep firing the OnSetBody event until
it has received the entire data. The Length parameter indicates the maximum number
of bytes that can be passed at one time. To indicate the end of the message body or
attachment, set Buffer to an empty string and Length to 0.
In some environments, such as Visual J++, the new value assigned to the Buffer
and IsFile parameters can not be successfully retrieved by the control. In these
cases set UseProperty to True, and assign data to the SendData property instead of the Buffer
parameter, and the BodyAsFile property can be used in place of the IsFile
parameter. In this case the UseProperty property must be set to True before attempting to
create a message. In this case treat the SendData property exactly as you would the Buffer
parameter, and the BodyAsFile property exactly as you would the IsFile parameter.
If UseProperty is True the Length parameter will be ignored.
To abort the create message, set the Action property to ACTION_ABORT (or call the Abort
method) during this event. The action in progress will be canceled and no further such
events will occur.
Note for BinHex encoded files: A file that has to be encoded in binhex40 generally has
two parts, a data fork and a resource fork, the MIME ActiveX will fire the OnSetBody event
to get the data fork first and then it will fire the OnSetBody event again to get for the
resource fork. If there is no resource fork then the application must set the Buffer
parameter to an empty string and the Length parameter to 0.
Example
' HeaderInfo is a structure for the attachment name, encoding used and the
content type
' see the MIME sample for the definition
Sub Mime_OnSetBody (Buffer As String, Length As Integer, IsFile
As Integer)
' send message body
If MsgBodyDone = False Then
Buffer = Message
Length = Len(Message)
IsFile = 0 ' message body
MsgBodyDone = True
Exit Sub
End If
' send attachment filename
If AttachDone = False And HeaderIndex <> 0 Then
Buffer = HeaderInfo(Indx).FilePath
Length = Len(HeaderInfo(Indx).FilePath)
IsFile = 1 ' attachment
AttachDone = True
Else
Buffer = "" ' end of body or attachment
Length = 0
IsFile = 0
End If
End Sub
|