* This function will start an executable that deals with email. * I don't know of any file extension that can be used to test for the existence of the * executable beforehand! * So, just try a call and conclude that there's no email server if it returns false. * Parameters: * tcRecipient Recipient. E.g. "pvalenca@viafox.nl" * tcSubject Title. * tcBody Body text. * tcAttachment Name of to be attached file. However, advise is not to use it! * Result: * Whether or not it succeeded in starting the mailserver. * E.g.: * if not SendEMail( "pvalenca@viafox.nl", "Request for support", "Hi" ) * wait wind "Could not send an email" nowait * endif FUNCTION SendEMail lparameters tcRecipient, tcSubject, tcBody, tcAttachment local lcParm, lcBody, lnResult, lcRecipient, lcSubject lcRecipient = EncodeForEMail( OrDefault( m.tcRecipient , '' ) ) lcSubject = EncodeForEMail( OrDefault( m.tcSubject , '' ) ) lcBody = EncodeForEMail( OrDefault( m.tcBody , '' ) ) lcAttachment = EncodeForEMail( OrDefault( m.tcAttachment, '' ) ) * lcParm = "mailto:" + m.lcRecipient + ; "?Subject=" + m.lcSubject + ; "&" + "Body=" + m.lcBody + ; iif( not empty( m.lcAttachment ), ' &' + 'Attach="' + m.lcAttachment + '"', "" ) declare integer ShellExecute in shell32.dll ; integer nWinHandle, ; string cOperation, ; string cFileName, ; string cParameters, ; string cDirectory, ; integer nShowWindow lnResult = ShellExecute( 0, "Open", m.lcParm, "", "", 1 ) clear dlls ShellExecute RETURN ( m.lnResult >= 32 ) * Inspired by the routine UrlEncode from Rick Strahl, but entirely different. * See also: * - http://www.west-wind.com/presentations/shellapi/shellapi.asp * - http://www.faqs.org/rfcs/rfc2368.html * - UT: <B>Re: Automate email</B> Thread 826623 Message 832461 FUNCTION EncodeForEMail( tcString ) local lcString lcString = strtran( m.tcString, "%", "%25" ) && This one must be the first! lcString = strtran( m.lcString, "?", "%3F" ) lcString = strtran( m.lcString, "&", "%26" ) lcString = strtran( m.lcString, "=", "%3D" ) lcString = strtran( m.lcString, '"', "%22" ) lcString = strtran( m.lcString, chr(13)+chr(10), "%0D%0A" ) lcString = strtran( m.lcString, chr(13) , "%0D%0A" ) RETURN m.lcString * Returns the default if the types of the two parameters differ. * E.g. lcAlias = OrDefault( tcAlias, alias() ) function OrDefault lparameter tuExpr, tuDefault RETURN iif( type('m.tuExpr')=type('m.tuDefault'), m.tuExpr, m.tuDefault )