//-----------------------------------------------------------------------
METHOD SendViaEMail( oDbf, oPthRep ) CLASS TMpMailApp
LOCAL aEmails := HB_ATOKENS( oDbf:Send_To, iif( ";" $ oDbf:Send_To, ";", "," ) )
LOCAL oDoc := ::oProcess:Getodbf( "doctors" )
LOCAL cZipFile := Temp_Name( "zip" )
LOCAL cPass, oMail, oTmp
LOCAL aFiles := { oPthRep:cPdfFile }
LOCAL cPathNo := oDbf:PathNo
LOCAL nQueue := oDbf:Queue
LOCAL cSendTo := oDbf:Send_To
IF oPthRep:isJpg ;AADD( aFiles, oPthRep:cJpgFile ) ;ENDIF
IF oPthRep:IsTiff ;AADD( aFiles, oPthRep:cTifFile) ;ENDIF
IF oPthRep:isHtml ;AADD( aFiles, oPthRep:cHtmlFile ) ;ENDIF
IF oPthRep:isRtf ;AADD( aFiles, oPthRep:cRtfFile ) ;ENDIF
AEVAL( aEmails, { |e,n| aEmails[ n ] := ALLTRIM( e ) } )
oDoc:Seek( oDbf:Doc_id ) ;iif( oDoc:Found(), oDoc:Load(), oDoc:Blank() )
cPass := ALLTRIM( IIF( oDoc:fieldexist( "password" ) .AND. ;
!EMPTY( oDoc:VarPassword ), ;
oDoc:VarPassword, oDbf:Doc_id ) )
IF !hb_zipFile( cZipFile, aFiles, 9,,.t., cPass, .f., .f., .t. )
AEVAL( aFiles, { |e| fErase( e ) } )
ferase( cZipFile )
Logfile( "PtheMailsErrors.log", { "Error Creating .zip for case:", oDbf:PathNo } )
RETURN NIL
ENDIF
oMail := TMySmtp():New( ::cIp, ::nPort, ::lAuth, ::cUserName, ::cUserPass )
oMail:cReplyTo := ::cSender
oMail:nGMT := TimeZone() //-5 // Atlantic Standard Time (GMT -05:00)
oMail:aAttachments := aFiles //save file names to erase later
oMail:oSocket:lDebug := ::lDebug
oMail:oSocket:cLogFile := "smtp.log"
oMail:nDelay := ::nDelay
oMail:bConnecting := { || iif( oMail:oSocket:lDebug,;
logfile( oMail:oSocket:cLogFile, { cPathNo, "Connecting to SMTP server " + ::cSmtpServer } ), ) }
oMail:bConnected := { || iif( oMail:oSocket:lDebug, ;
logfile( oMail:oSocket:cLogFile, { cpathNo, "Sending eMail Via " + ::cSmtpServer } ), ) }
oMail:bDone := { || MailWasSent( cPathNo, nQueue, cSendto ),;
LogSuccessIntoAuditLog( cPathNo, cSendto ),;
fErase( cZipFile ),;
AEVAL( oMail:aAttachments, { |e| ferase( e ) } ),;
oMail:End(), ;
oMail := Nil,;
AEVAL( aFiles, { |e| fErase( e ) } ) }
oMail:bFailure := { || IncAttempts( cPathNo, nQueue, cSendto ) ,;
fErase( cZipFile ),;
AEVAL( oMail:aAttachments, { |e| ferase( e ) } ),;
iif( oMail != Nil .and. oMail:oSocket:lDebug, ;
logfile( oMail:oSocket:cLogFile, { "Failure to send email" } ), ),;
iif( oMail != Nil, ( oMail:end(), oMail := Nil ), ) }
oMail:SendMail( ::cSender, aEmails, ;
"Pathology report attached intended for " + ;
alltrim( StrCapFirst( oDoc:Last ) ) + ", " + alltrim( StrCapFirst( oDoc:First ) )+ ;
". Please use your password to open zipped file." + Chr( 13 ) + Chr( 12 ) + ;
"The information contained in this e-mail is privileged and confidential, intended only for the use of "+;
"the individual or entity named above. If the reader of this message is not the intended recipient, "+;
"you are hereby notified that any dissemination, distribution or copy of this information is strictly "+;
"prohibited.", ;// Msg Text
"Pathology Report", ; // Subject
{ cZipFile },,, .t. ) // attached files
RETURN NIL