Rick Lipkin wrote:I failed to declare oOutMail as a variable .. ( can't believe I did that )
oOutMail:bFailure := { || LogFile( "mail.log", {oOutMail:aTo:[1] + " Failed"}), oOutMail:nStatus := ST_QUIT }
if oMail:nStatus == ST_QUIT .or. oMail:nStatus == ST_DONE
MailWasSent( aElem )
ncount++
Else
IncAttempts( aElem )
endif
cScript := "SELECT pathno, Send_To, Queue, Attempts FROM plmail "+;
"WHERE DateTime_Sent IS NULL "+;
"AND TIMESTAMPDIFF( SQL_TSI_HOUR, creation, now() ) >= " + Str(oApp:nLatency) + ;
" AND Attempts < " + str( oApp:nMaxAttempts ) + ;
" ORDER BY Queue"
// different session status
#define ST_INIT 0
#define ST_CONNECTED 1
#define ST_RESET 2
#define ST_MAILFROM 3
#define ST_RCPTTO 4
#define ST_DATA 5
#define ST_SENT 6
#define ST_QUIT 7
#define ST_DONE 8
#define ST_ERROR 9
oOutMail:bFailure := { || LogFile( "Failed"), oOutMail:nStatus := 7 }
...
//-------------------
Static Func LogFile( cFAILED )
IF EMPTY( cFAILED )
cFAILED := "NO"
ENDIF
MsgInFo( cFAILED )
RETURN(NIL)
// use this public variable
// returns from tsmtp() .T.
lFAIL := .F.
oWndMdi:SetMsg( "Sending Reporting noticication to "+cTO )
WSAStartup()
oOutMail := TSmtp():New( cIP := GetHostByName( cHOST ) )
oOutMail:bConnecting := { || oWndMdi:SetMsg( "Connecting to "+cHOST ) }
oOutMail:bConnected := { || oWndMdi:SetMsg( "Connected" ) }
oOutMail:bDone := { || oWndMdi:SetMsg( "Message sent successfully" ) }
oOutMail:bFailure := { || oOutMail:nStatus := 7 } // keep this
oOutMail:SendMail( cFROM,; // From
{ cTO },; // To
cMESSAGE,; // Msg Text
cSUBJECT,;
{"C:\DBTMP\PROJINFO.BAT"},; // attachment
aCC, ; // cc array
{ }, ; // bc
.F., ; // no return receipt
NIL ) // not html
// wait for e-mail to be sent to get lfail value
SysWait(1)
IF lFAIL = .T.
cSUBJECT := "Email Error FAILED to be Sent"
* MsgInfo( cSUBJECT )
ENDIF
SysReFresh()
// create e-mail record //
cEID := _GenEid(2)
IF cEID = "BOGUS"
ELSE
oRsEmail:AddNew()
oRsEmail:Fields("emaileid"):Value := cEID
oRsEmail:Fields("projecteid"):Value := oRsProj:Fields("projecteid"):Value
oRsEmail:Fields("date_sent"):Value := dtoc(DATE())+" "+time()
oRsEmail:Fields("email_from"):Value := cFROM
oRsEmail:Fields("email_to"):Value := cTO //+", "+AEVAL(aCC)
oRsEmail:Fields("subject"):Value := SUBSTR(cSUBJECT+SPACE(50),1,49)
oRsEmail:Fields("message"):Value := cMESSAGE
oRsEmail:Fields("attachments"):Value := "ProjInfo.Bat"
IF lFAIL = .T.
oRsEmail:Fields("address_error"):Value := "Y"
ELSE
oRsEmail:Fields("address_error"):Value := "N"
ENDIF
oRsEmail:Update()
ENDIF
Case ::nStatus == ST_MAILFROM .or. ::nStatus == ST_RCPTTO
If cReply == "250" .or. cReply == "251" // Server happy with our repsonse
If ::nTo <= Len( ::aTo )
oSocket:SendData( StrTran( "RCPT TO:<%>", "%", CleanEMail( ::aTo[ ::nTo ] ) ) + ;
CRLF )
::nStatus := ST_RCPTTO
::nTo++
Elseif ::nCC <= Len( ::aCC )
oSocket:SendData( StrTran( "RCPT TO:<%>", "%", CleanEMail( ::aCC[ ::nCC ] ) ) + ;
CRLF )
::nStatus := ST_RCPTTO
::nCC++
Elseif ::nBCC <= Len( ::aBCC )
oSocket:SendData( StrTran( "RCPT TO:<%>", "%", CleanEMail( ::aBCC[ ::nBCC ] ) ) + ;
CRLF )
::nStatus := ST_RCPTTO
::nBCC++
Else
::nStatus := ST_DATA
oSocket:SendData( "DATA" + CRLF )
Endif
Else
// failure here is e-mail address is bad
// Rick added to trap
lFAIL := .T.
Msginfo( "Message Failed to be sent because of a Bad Address")
::Failure( oSocket, nWSAError, cReply )
Endif
took your suggestion and I must have some syntactical error where 7 is ST_QUIT
Your suggestion :
oOutMail:bFailure := { || LogFile( "mail.log", {oOutMail:aTo:[1] + " Failed"}), oOutMail:nStatus := ST_QUIT }
Trying to get it to work .. unfortunitly the LogFile fires everytime good or bad ??
If ::bFailure != nil
Eval( ::bFailure, oSocket, nWSAError, cReply )
Endif
oOutMail:bFailure := { || LogFile( "Failed"), oOutMail:nStatus := 7 }
..
//-------------------
Static Func LogFile( cFAILED )
IF EMPTY( cFAILED )
cFAILED := "NO"
ENDIF
MsgInFo( cFAILED )
RETURN(NIL)
//----------------------------------------------------------------------------//
METHOD Failure( oSocket, nWSAError, cReply ) CLASS TSmtp
Local aStage := { "ST_INIT", ;
"ST_CONNECTED", ;
"ST_RESET", ;
"ST_MAILFROM", ;
"ST_RCPTTO", ;
"ST_DATA", ;
"ST_SENT", ;
"ST_QUIT", ;
"ST_DONE", ;
"ST_ERROR", ;
"ST_AUTH0", ;
"ST_AUTH", ;
"ST_USER", ;
"ST_PASS" }
DEFAULT oSocket := ::oSocket, nWSAError := WSAGetLastError(), cReply := ""
If ::nStatus >= ST_INIT .and. ::nStatus <= ST_LAST
::cError := "Stage: " + aStage[ ::nStatus + 1 ] + CRLF
Else
::cError := ""
Endif
::nStatus := ST_ERROR
::cError += "IP Address: " + ::cIPServer + CRLF + CRLF
AEval( ::acReply, {|cReply| ::cError += cReply + CRLF } )
If nWSAError # 0
::cError += "WSA Error Code: " + AllTrim( Str( nWSAError ) )
Endif
If ::bFailure != nil
Eval( ::bFailure )
Endif
oSocket:End()
return Self
//----------------------------------------------------------------------------//
METHOD Failure( oSocket, nWSAError, cReply ) CLASS TSmtp
Local aStage := { "ST_INIT", ;
"ST_CONNECTED", ;
"ST_RESET", ;
"ST_MAILFROM", ;
"ST_RCPTTO", ;
"ST_DATA", ;
"ST_SENT", ;
"ST_QUIT", ;
"ST_DONE", ;
"ST_ERROR", ;
"ST_AUTH0", ;
"ST_AUTH", ;
"ST_USER", ;
"ST_PASS" }
DEFAULT oSocket := ::oSocket, nWSAError := WSAGetLastError(), cReply := ""
If ::nStatus >= ST_INIT .and. ::nStatus <= ST_LAST
::cError := "Stage: " + aStage[ ::nStatus + 1 ] + CRLF
Else
::cError := ""
Endif
::nStatus := ST_ERROR
::cError += "IP Address: " + ::cIPServer + CRLF + CRLF
AEval( ::acReply, {|cReply| ::cError += cReply + CRLF } )
If nWSAError # 0
::cError += "WSA Error Code: " + AllTrim( Str( nWSAError ) )
Endif
// suggested change here ...
If ::bFailure != nil
Eval( ::bFailure, oSocket, nWSAError, cReply )
Endif
oSocket:End()
return Self
oOutMail:bFailure := { | oSocket, nError, cReply | LogFile( "log.txt", { nError, cReply } ), oOutMail:nStatus := 7 }
Case ::nStatus == ST_MAILFROM .or. ::nStatus == ST_RCPTTO
If cReply == "250" .or. cReply == "251" // Server happy with our repsonse
If ::nTo <= Len( ::aTo )
oSocket:SendData( StrTran( "RCPT TO:<%>", "%", CleanEMail( ::aTo[ ::nTo ] ) ) + ;
CRLF )
::nStatus := ST_RCPTTO
::nTo++
Elseif ::nCC <= Len( ::aCC )
oSocket:SendData( StrTran( "RCPT TO:<%>", "%", CleanEMail( ::aCC[ ::nCC ] ) ) + ;
CRLF )
::nStatus := ST_RCPTTO
::nCC++
Elseif ::nBCC <= Len( ::aBCC )
oSocket:SendData( StrTran( "RCPT TO:<%>", "%", CleanEMail( ::aBCC[ ::nBCC ] ) ) + ;
CRLF )
::nStatus := ST_RCPTTO
::nBCC++
Else
::nStatus := ST_DATA
oSocket:SendData( "DATA" + CRLF )
Endif
Else
// failure here is e-mail address is bad
// RIck added to trap
lFAIL := .T.
Msginfo( "Message Failed to be sent because of a Bad Address")
::Failure( oSocket, nWSAError, cReply )
Endif
10/07/2008 16:35:41: 0 550
10/07/2008 16:36:01: 10048
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: Google [Bot] and 65 guests