Hello Jan,
It's pretty old code, because as we have our own e-mail program, sending an e-mail to Outlook is no longer necessary in our programs, but this should basically do the trick:
Dick
FUNCTION SendMailOutlook(cSubject,cText,aFiles,aEmail) AS LOGIC
LOCAL cbOldErrorBlock AS CODEBLOCK
LOCAL oOutlook AS USUAL
LOCAL oMail AS USUAL
LOCAL oAttachment AS USUAL
LOCAL nTeller AS DWORD
LOCAL lRetVal AS LOGIC
lRetVal :=TRUE // Init some variables
IF lRetVal .AND. Empty(cSubject) // Check layout
END
IF lRetVal .AND. Empty(cText)
END
IF lRetVal
cbOldErrorBlock:=ErrorBlock() // Save previous error handler
BEGIN SEQUENCE
ErrorBlock({|X|DummyFunction(X)}) // Create new error handler
oOutlook:=OLEAutoObject{"Outlook.Application"} // Start Outlook
oMail:=oOutlook:CreateItem(0) // Create mail
RECOVER // Exception
lRetVal:=FALSE
END
ErrorBlock(cbOldErrorBlock) // Resore old error handler
IF lRetVal // All ok
FOR nTeller:=1 UPTO ALen(aEmail) // For sender objMail:add addresses to email
oMail:Recipients:Add(aEmail[nTeller])
NEXT nTeller
IF oMail:Recipients:ResolveAll() // Check if addresses are ok
oMail:Subject:=cSubject // Add subejct
oMail:Body:=cText // and body
oAttachment:=oMail:Attachments // and attachments:
FOR nTeller:=1 UPTO ALen(aFiles)
IF File(aFiles[nTeller])
oAttachment:Add(aFiles[nTeller])
END
NEXT nTeller
oMail:Send() // send
ELSE
WarningBox{NIL,Vt(MSG_EMAILMESSAGE,"Email message"),;
Vt(MSG_NOTALLEMAILADROK,"Not all email-adresses are correct")}:Show()
lRetVal:=FALSE
ENDIF
ELSE
WarningBox{NIL,Vt(MSG_EMAILMESSAGE,"Email message"),;
Vt(MSG_OUTLOOKNOTOK,"Outlook has not been installed properly!")}:Show()
lRetVal:=FALSE
ENDIF
END
RestoreDefaultPath("")
RETURN lRetVal