DEFINE CLASS sendblatmail as custom ************************************ #IF .F. LOCAL this as sendblatmail OF blatmail.prg #ENDIF icBlatDllFolder = <folderwheretheDLLisslocated> && MODIFY THIS!! icFrom = '' icTo = '' icCC = '' icBCC = '' icSubject = '' inReturnCode = 0 icErrorMessage = '' icBodyFile = '' icMessageString = '' ilSendTheString = .F. ilSendTheFile = .F. icFiletoAttach = '' && the following are entered in registry if BLAT installation info not found icSMTP_Server = 'mail.mySMTPServer.com' && MODIFY THIS icSender = 'myUserName@mydomain.com' && MODIFY THIS icTry = '2' icSMTP_Port = '25' ********************************************************* FUNCTION init(tcBlatDllFolder,tcFrom,tlSendTheString) ********************************************************* LOCAL lcBlatDllFile IF !EMPTY(tcBlatDllFolder) this.icBlatDllFolder = ADDBS(TRIM(tcBlatDllFolder)) ENDIF IF !EMPTY(tcFrom) this.icFrom = TRIM(tcFrom) endif IF EMPTY(tlSendTheString) this.ilSendTheString = .F. this.ilSendTheFile = .T. ELSE this.ilSendTheString = tlSendTheString this.ilSendTheFile = !tlSendTheString ENDIF lcBlatDllFile = ADDBS(TRIM(this.icBLATDLLFOLDER))+"BLAT.DLL" IF !FILE(lcBlatDLLFile) RETURN .F. ENDIF CLEAR DLLS Send && I have this verify all the BLAT registry items exist - if not, it sets them so no blat config is needed - this.CheckRegistry() DECLARE INTEGER Send in &lcBlatDllFile STRING blatstring ********************************************************* ENDFUNC && INIT ********************************************************* ********************************************************* FUNCTION CheckRegistry() ********************************************************* LOCAL OReg oReg = .NULL. oReg = NEWOBJECT("registryinterface","registryinterface.prg") && Check for required keys - if not found, set! IF LEFT(oReg.check_registry_value("SMTP Server","software\Examinetics\NewDG\Blat"),4) = 'KGNO' oReg.set_registry_value("SMTP Server",this.icSMTP_SERVER,"software\Public Domain\Blat") endif IF LEFT(oReg.check_registry_value("SMTP Port","software\Examinetics\NewDG\Blat"),4) = 'KGNO' oReg.set_registry_value("SMTP Port",this.icSMTP_PORT,"software\Public Domain\Blat") endif IF LEFT(oReg.check_registry_value("Try","software\Examinetics\NewDG\Blat"),4) = 'KGNO' oReg.set_registry_value("Try",this.icTRY,"software\Public Domain\Blat") endif *!* IF LEFT(oReg.check_registry_value("Sender","software\Examinetics\NewDG\Blat"),4) = 'KGNO' oReg.set_registry_value("Sender",this.icSENDER,"software\Public Domain\Blat") *!* ENDIF RELEASE oReg RETURN .T. ********************************************************* ENDFUNC && CHECKREGISTRY ********************************************************* ********************************************************* FUNCTION send(tcTo,tcCC,tcBCC,tcSubject,tcMessageString,tcBodyFile,tlSendTheString,tcFileToAttach,tcFrom) ********************************************************* LOCAL llRetVal LOCAL lcBlatCommandString LOCAL lnResult IF EMPTY(tcTo) AND EMPTY(this.icTO) && nowhere to send! this.inReturnCode = -1 this.icErrorMessage = 'TO is not specified!' RETURN .F. ELSE IF !EMPTY(tcto) this.icto = ALLTRIM(tcTo) endif endif IF !EMPTY(tcCC) this.icCC = tcCC ENDIF IF !EMPTY(tcBCC) this.icBCC = tcBCC endif IF !EMPTY(tcSubject) this.icSubject = TRIM(tcSubject) ENDIF IF !EMPTY(tcMessageString) this.icMessageString = TRIM(tcMessageString) endif IF !EMPTY(tcBodyFile) this.icBodyFile = allTRIM(tcBodyFile) IF !FILE(tcBodyFile) this.inReturnCode = -1 this.icErrorMessage = 'Message Body File "' + tcBodyFile + '" does not exist!' RETURN .f. ENDIF ENDIF IF !EMPTY(tlSendTheString) this.ilSendtheString = tlSendTheString this.ilSendTheFile = !tlSendTheString endif IF !EMPTY(tcFileToAttach) *!* IF FILE(tcFileToAttach) this.icFileToAttach = tcFileToAttach *!* ELSE *!* this.icErrorMessage = IIF(!EMPTY(this.icErrorMessage),this.icErrorMessage+' :: ' + 'File to attach "' + tcFileToAttach + '" was not found!','File to attach "' + tcFileToAttach + '" was not found!') *!* endif endif lcBlatCommandString = '' lnResult = 0 llRetVal = .F. && build the string lcBlatCommandString = IIF(this.ilsenDTHEFILE,this.icBODYFILE+' ','NUL ') lcBlatCommandString = lcBlatCommandString + IIF(!EMPTY(this.icTO),'-to '+this.icTO + ' ','') lcBlatCommandString = lcBlatCommandString + IIF(!EMPTY(this.icCC),'-cc '+this.icCC+' ','') lcBlatCommandString = lcBlatCommandString + IIF(!EMPTY(this.icBCC),'-bcc '+this.icBCC + ' ','') lcBlatCommandString = lcBlatCommandString + '-f '+ IIF(!EMPTY(tcFrom),tcFrom,this.icFrom) + ' ' lcBlatCommandString = lcBlatCommandString + IIF(!EMPTY(this.icsUBJECT),'-s "'+this.icSUBJECT +'" ','') lcBlatCommandString = lcBlatCommandString + IIF(this.ilsendthestring,'-body "'+this.icmessagestring+'" ','') lcBlatCommandString = lcBlatCommandString + IIF(!EMPTY(this.icFileToAttach),'-attach '+ this.icFileToAttach,'') WAIT 'Sending mail to '+this.icTo+IIF(!EMPTY(this.iccc),'+ '+this.iccc,'') +IIF(!EMPTY(this.icbcc),'+ '+this.icbcc,'') + '..' WINDOW nowait lnResult = Send(lcBlatCommandString) WAIT clear IF lnResult = 0 llRetVal = .T. this.icFrom = '' this.icTo = '' this.icCC = '' this.icBCC = '' this.icSubject = '' this.icErrorMessage = '' this.icBodyFile = '' this.icMessageString = '' this.ilSendTheString = .F. this.ilSendTheFile = .F. this.icFiletoAttach = '' ELSE this.inReturnCode = lnResult lRetVal = .F. endif RETURN llRetVal ********************************************************* ENDFUNC && send ********************************************************* ********************************************************* FUNCTION DESTROY ********************************************************* CLEAR DLLS Send ********************************************************* ENDFUNC && DESTROY ********************************************************* ********************************************************* ENDDEFINE && class sendblatmail *********************************************************