****************************************************************************** *-- Sends a mail through MAPI. *-- Parameter cAttach has to be a full path file name. ****************************************************************************** function sendMAPIMail(cSubject, cBody, cRecipient, cAttach) local lcDirectory, loMAPISession, loMAPIMessage do case case pCount() < 3 *-- Include here your favorite message return .f. case pCount() < 4 cAttach = '' endcase *-- The MAPI server can change the directory if it has to be initialized lcDirectory = set('directory') loMAPISession = createObject('MSMAPI.MAPISession.1') loMAPIMessage = createObject('MSMAPI.MAPIMessages.1') *-- Signon procedure with loMAPISession .Signon() *-- Checks that the session has been initialized, and assigns the id *-- to the message object if (.SessionID > 0) loMAPIMessage.SessionID = .SessionID else wait window "Could not initalize MAPI session" return .f. endif endwith *-- Sends the message with loMAPIMessage .Compose() .RecipDisplayName = allTrim(cRecipient) .RecipType = 1 .ResolveName() .MsgSubject = allTrim(cSubject) .MsgNoteText = allTrim(cBody) *-- Attach the file to the message. You can attach several files *-- by only adding a FOR...ENDFOR that loops through the files *-- in the attach string, or yu can modify the function to pass *-- an array of file names if NOT isBlank(cAttach) AND file(cAttach) .AttachmentIndex = loMAPIMessage.AttachmentCount .AttachmentName = right(cAttach, len(cAttach) - rat('\', cAttach)) .AttachmentPathName = cAttach endif .Send(.f.) endwith loMAPISession.Signoff() set directory to (lcDirectory) return .t.This is a very simple function and you can improve it in many ways, but it shows a simple way to use MAPI to send a message.