Trapping SMTP e-mail error

Trapping SMTP e-mail error

Postby Rick Lipkin » Wed Oct 01, 2008 8:59 pm

To All

I am trying to trap an SMTP ( tsntp class ) error when I have a message that failed to send... generally because of a bad email address ..

Here is my code .. where do I need to place my try, catch, end try ?? it does not work where you see it now ??

Rick Lipkin
Code: Select all  Expand view  RUN
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" ) }

        TRY
        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
        CATCH oERR
           lFAIL := .T.
        END TRY

        IF lFAIL = .T.
           cSUBJECT := "Email Error FAILED to be Sent"
           MsgInfo( cSUBJECT )
        ENDIF

        SysReFresh()
User avatar
Rick Lipkin
 
Posts: 2666
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Postby Antonio Linares » Wed Oct 01, 2008 10:42 pm

Rick,

You could wait to send the email until bConnected is invoked, and if not, then after waiting for some time, don't send the email.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42203
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Antonio Linares » Wed Oct 01, 2008 10:43 pm

oOutMail:bConnected = { || lSendIt := .T. }
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42203
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Rick Lipkin » Wed Oct 01, 2008 11:19 pm

Antonio

Where my code can fail is if the person ( internally ) is not in the address book. I have no problems connecting or resolving the host .. I may have 5 or more cc's and if one of them is spelled incorrectly .. the whole thing blows up with a 'run time' and I there is no recovery.

Our SMTP server only looks at our Agency's LDAP and apparently if one of the adressee's is not valid .. the message fails.

I was looking to trap the return error .. I do get a EFAIL so I know there is a way to trap .. just don't know where ???

Rick
User avatar
Rick Lipkin
 
Posts: 2666
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Postby Antonio Linares » Wed Oct 01, 2008 11:26 pm

Rick,

> the whole thing blows up with a 'run time'

Is it a system error ? Or an application error ?

Please copy it here, thanks
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42203
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Rick Lipkin » Thu Oct 02, 2008 12:05 am

Antonio

It will be in the morning ... I will show you the resulting error from the above code.

Thanks
Rick
User avatar
Rick Lipkin
 
Posts: 2666
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Postby Rick Lipkin » Thu Oct 02, 2008 8:04 pm

Antonio

Here is our last private message .. perhaps this will be of help to others..

Rick,

> In the Tsmpt class code .. is there a line there when I can try, catch, end try to trap this error ??

No, because it is not an execution runtime error. It is an error code
returned by MapiSendmail()

best regards,

Antonio Linares
www.fivetechsoft.com
User avatar
Rick Lipkin
 
Posts: 2666
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Postby James Bott » Fri Oct 03, 2008 3:02 am

Rick,

There must be a way you can check to see if the mail address is valid (as a separate function). I would Google it.

Regards,
James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby Rick Lipkin » Fri Oct 03, 2008 12:55 pm

James

Our SMTP checks our LDAP for addresses and the mail function just returns the error from the server ..

Antonio is on the right track in that I can not check the internals of SMTP, however, when you look at the tsntp class .. you will see

DATA bFailure AS CODEBLOCK INIT NIL

and ::bFailure is evaluared in method

METHOD Failure( oSocket, nWSAError, cReply ) CLASS TSmtp

and it looks like my error 550 is coming from


Code: Select all  Expand view  RUN
Case ::nStatus == ST_QUIT
         If cReply == "221" .or. cReply == "500" .or. cReply == "502" .or. cReply == "550"  // 500/550 is "unknown command" and doesn't really matter at this stage
            ::nStatus := ST_DONE
            If ::bDone != nil
               Eval( ::bDone )
            Endif
            ::oSocket:End()
         Else
            ::Failure( oSocket, nWSAError, cReply )
         Endif


In my code

Code: Select all  Expand view  RUN
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" ) }

       * TRY
        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
       * CATCH oERR
       *    lFAIL := .T.
       * END TRY

        IF lFAIL = .T.
           cSUBJECT := "Email Error FAILED to be Sent"
           MsgInfo( cSUBJECT )
        ENDIF

        SysReFresh()


it appears you can evaluate the object oOutMail as in

Code: Select all  Expand view  RUN
oOutMail:bDone       = { || oWndMdi:SetMsg( "Message sent successfully" ) }


oOutMail:bFalure ... and this may be the way I can trap my error .. however ( dumb question ) .. How can I evaluate this object to get its value ??

Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2666
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Postby Antonio Linares » Fri Oct 03, 2008 1:30 pm

Rick,

I thought you were using MAPI instead of Class TSmtp, my mistake, sorry.

As you are already using the SMTP protocol, we could modify the Class to check that the recipient email address exists:

http://james.apache.org/server/rfclist/smtp/rfc0821.txt

"The second step in the procedure is the RCPT command.

RCPT <SP> TO:<forward-path> <CRLF>

This command gives a forward-path identifying one recipient.
If accepted, the receiver-SMTP returns a 250 OK reply, and
stores the forward-path. If the recipient is unknown the
receiver-SMTP returns a 550 Failure reply. This second step of
the procedure can be repeated any number of times."
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42203
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Antonio Linares » Fri Oct 03, 2008 1:39 pm

Rick,

Please try this:

oOutMail:bFailure := { || oOutMail:nStatus := ST_QUIT }
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42203
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Rick Lipkin » Fri Oct 03, 2008 4:45 pm

Antonio

Please forgive my ignorance .. where do you want me to place this ??
Rick,

Please try this:

oOutMail:bFailure := { || oOutMail:nStatus := ST_QUIT }
_________________
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Rick Lipkin
 
Posts: 2666
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Postby Antonio Linares » Fri Oct 03, 2008 5:01 pm

Rick,

Just after:

oOutMail:bDone = { || oWndMdi:SetMsg( "Message sent successfully" ) }
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42203
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Rick Lipkin » Fri Oct 03, 2008 6:10 pm

Antonio

oOutMail:bFailure := { || oOutMail:nStatus := 7 } is what I inserted .. st_quit was defined in tsmpt as 7

and I got a run time of this ( unfortunitly ) :(

Rick



Code: Select all  Expand view  RUN
Application
===========
   Path and name: C:\FOX\PMOSQL\PmoW32.Exe (32 bits)
   Size: 2,070,528 bytes
   Time from start: 0 hours 0 mins 16 secs
   Error occurred at: 10/03/2008, 13:52:17
   Error description: Error BASE/1003  Variable does not exist: OOUTMAIL

Stack Calls
===========
   Called from: RPTVIEW.PRG => (b)_DOIT(1927)
   Called from: TSMTP.PRG => TSMTP:FAILURE(517)
   Called from: TSMTP.PRG => TSMTP:ONREAD(290)
   Called from: TSMTP.PRG => (b)TSMTP:NEW(131)
   Called from: TSOCKET.PRG => (b)TSOCKET:TSOCKET(77)
   Called from:  => TSOCKET:ONREAD(0)
   Called from: TSOCKET.PRG => TSOCKET:HANDLEEVENT(229)
   Called from: TSOCKET.PRG => (b)TSOCKET:NEW(121)
   Called from: .\source\classes\WINDOW.PRG => TMDIFRAME:ASYNCSELECT(0)
   Called from:  => TMDIFRAME:HANDLEEVENT(0)
   Called from: .\source\classes\WINDOW.PRG => _FWH(0)
   Called from:  => DIALOGBOX(0)
   Called from: .\source\classes\DIALOG.PRG => TDIALOG:ACTIVATE(0)
   Called from: PROJVIEW.PRG => _PROJVIEW(520)
   Called from: PROJBROW.PRG => (b)PROJMENU(405)
   Called from: .\source\classes\MENU.PRG => TMENU:COMMAND(0)
   Called from: .\source\classes\WINDOW.PRG => TWINDOW:COMMAND(0)
   Called from: .\source\classes\MDIFRAME.PRG => TMDIFRAME:COMMAND(0)
   Called from:  => TMDIFRAME:HANDLEEVENT(0)
   Called from: .\source\classes\WINDOW.PRG => _FWH(0)
   Called from:  => WINRUN(0)
   Called from: .\source\classes\WINDOW.PRG => TMDIFRAME:ACTIVATE(0)
   Called from: MAIN.PRG => MAIN(310)

System
User avatar
Rick Lipkin
 
Posts: 2666
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Postby Antonio Linares » Fri Oct 03, 2008 7:27 pm

Rick,

Have you defined oOutMail as a private variable ?

If yes, please change it to local, static or public. I would recommend local.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42203
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 13 guests