DEFINE CLASS sendblatmail as custom ************************************ #IF .F. LOCAL this as sendblatmail OF blatmail.prg #ENDIF icFrom = '' icTo = '' icCC = '' icBCC = '' icSubject = '' inReturnCode = 0 icErrorMessage = '' icBodyFile = '' icMessageString = '' ilSendTheString = .F. ilSendTheFile = .F. icFiletoAttach = '' icBlatDllFolder = "C:\program files\blat" *!* set this to where BLAT.DLL is located icSMTP_Server = 'mail.myserver.com' *!* use the address of your SMTP server here ********************************************************* 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 DECLARE INTEGER Send in &lcBlatDllFile STRING blatstring ********************************************************* ENDFUNC && INIT ********************************************************* ********************************************************* 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) this.icFileToAttach = tcFileToAttach 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 *********************************************************