FUNCTION SendMailOutlook( ) /* This is a function to send email with outlook The sample is provided 'As it is' and is free of any copyrights. For information or comments email to: cavo@marti.nl This and other samples can be found at 81.26.209.134/cavo Regards, Marc Verkade Marti BV - Naaldwijk - Netherlands Usage: Cut and Paste this function in your App Include OLE-library Change Vars cSubject,cText,cFile,aEmailAdresses Call function SendMail() from anywhere within your program You can change the function and add some parameters! Revision Info: 01-05-2001 Changed function name 07-03-2001 Initial creation of sample Outlook mail routines extracted from MC_Lib for VO */ LOCAL cSubject AS STRING LOCAL cText AS STRING LOCAL cFile AS STRING LOCAL aEmailAdresses AS ARRAY LOCAL cbOldErrorBlock AS CODEBLOCK LOCAL oOutlook AS USUAL LOCAL oMail AS USUAL LOCAL oAttachment AS USUAL LOCAL nCount AS DWORD LOCAL lContinue AS LOGIC // Init vars cSubject :="This a an email test for VO and Outlook" cText :="Testing automatisc creation of email" cFile :="C:\Autoexec.Bat" aEmailAdresses :={"cavo@marti.nl"} lContinue :=TRUE // Init outlook object oOutlook:=Oleautoobject{"Outlook.Application"} // Save old Error handler cbOldErrorBlock:=ErrorBlock() BEGIN SEQUENCE // Create new handler ErrorBlock({|X| DummyFunction(X)}) // Create new mailitem oMail:=oOutlook:CreateItem(0) RECOVER // There is an error lContinue := FALSE END // Reset old handler ErrorBlock(cbOldErrorBlock) // OK IF lContinue // Add adresses FOR nCount:=1 UPTO ALen(aEmailAdresses) oMail:Recipients:Add(aEmailAdresses[nCount]) NEXT nCount // Check adresses IF oMail:Recipients:ResolveAll() // Set subject oMail:Subject:=cSubject oMail:Body:=cText // Attach a file oAttachment:=oMail:Attachments oAttachment:Add(cFile) // Send! oMail:Send() Warningbox{,"Email","Email is send to cavo@marti.nl!"}:show() ELSE Warningbox{,"Email","Email adres is not correct!"}:show() lContinue := FALSE ENDIF ENDIF RETURN lContinue FUNCTION DummyFunction( ) // Dummy function for errorhandler RETURN NIL