This is code from a class I have for MAPI stuff. I instantiate the session and message objects in the init of the class like this:
This.oSession = CreateObject('MSMAPI.MAPISession')
This.oMessage = CreateObject('MSMAPI.MAPIMessages')
Then I have properties for all the parts of a message and programmatically set them before calling a custom Send method. The send method is as follows:
*set step on
WAIT WINDOW NOWAIT "Please wait ... Logging Into Mail"
* Signon to mail
IF !This.lLoggedIn AND !EMPTY(This.cProfile)
This.oSession.UserName = This.cProfile
This.oSession.Signon
This.lLoggedIn = .T.
ELSE
RETURN .F.
ENDIF
* If the session ID is not valid, do not go any further
IF This.oSession.SessionID > 0
This.oMessage.SessionID = This.oSession.SessionID
ELSE
WAIT WINDOW NOWAIT "Login Failed"
RETURN .F.
ENDIF
* Start a new message
This.oMessage.Compose
* Increment the Recipient index
This.oMessage.RecipIndex = 0
* Set the Recipient name and resolve
IF EMPTY(This.cSendTo)
RETURN .F.
ENDIF
This.oMessage.RecipDisplayName = This.cSendTo
This.oMessage.ResolveName
IF !EMPTY(This.cSubject)
This.oMessage.MsgSubject = This.cSubject
ENDIF
IF !EMPTY(This.cText)
This.oMessage.MsgNoteText = This.cText
ENDIF
IF !EMPTY(This.cAttachment)
This.oMessage.AttachmentPathname = This.cAttachment
ENDIF
WAIT WINDOW NOWAIT "Sending Message ... "
This.oMessage.Send(0)
WAIT WINDOW NOWAIT "Message Sent!"
RETURN .T.
You should be able to get the idea from this, if not feel free to write back. If anyone thinks it is useful, let me know and I'll submit the class to UT. The thing I liked about my approach (other than it was mine <g>) was it encapsulated the mechanics of the 2 objects into one ie Message and Session were rolled into one object which is the way I think of MAPI anyway.
"Coles Law: Thinly sliced cabbage"
Oct 31 = Dec 25