Problem with tsmtp-class

Problem with tsmtp-class

Postby gkuhnert » Thu Oct 09, 2008 7:25 am

Hi,

when I try to send e-Mails with tsmp-class when authentification is required, no e-Mail will be send. Following code am I using (modified testsmtp.prg):

Code: Select all  Expand view
function SendMail()

   local oOutMail, cIP
   local cHost := "smtp.strato.de"
   local cEmail := "test@ctosoftware.de"
   local cUser := "test"
   local cPass := "test"

   oWnd:SetMsg( "Sending Internet email..." )

   WSAStartup()
   oOutMail := TSmtp():New( cIP := GetHostByName( cHost ), 25 , .t., cUser, cPass  )

   oOutMail:bConnecting = {|| msginfo("connecting...")} //{ || oWnd:SetMsg( "Connecting to "+cHost ) }
   oOutMail:bConnected  = {|| msginfo("connected!")}
   oOutMail:bDone       = {|| msginfo("done!")}

   oOutMail:bFailure    = {|| msginfo("error detected!")}

   oOutMail:lAuth := .t.
   oOutMail:lDoAuth := .t.

   oOutMail:SendMail( cEmail,;     // From
                      { "kuhnert@ctosoftware.de" },; // To
                      "It is working!!!",;              // Msg Text
                      "Testing FiveWin Class TSmtp enhancements",; // Subject
                       )  // attached files

   oOutMail:End()

msginfo("oOutmail closed")

return nil


The msginfo "connecting..." does appear, but after that, the msginfo "oOutmail closed" directly appears, without sending an e-mail...


The statements oOutmail:lAuth = .t. and oOutmail:lDoAuth = .t. seem to be needed because a small error in the new-method of tsmtp-class:

Code: Select all  Expand view
METHOD New( cIPServer, nPort, lAuth, cUser, cPassword ) CLASS TSmtp

   #ifdef __XPP__
      #undef New
   #endif

   Default nPort := 25, ;
           lAuth := .F., ;                       // IBTC
           cUser := "", ;                        // [jlalin]
           cPassword := ""                       // [jlalin]

   If Empty( cIPServer )                         // nil or ""
      cIPServer := "0.0.0.0"
   Endif

   ::lAuth      := .F.      // <<----- Here lAuth is set to .f. irrespective of the
                            // lAuth-parameter coming through the call of the new()-method
   ::lDoAuth    := lAuth                         // IBTC
   ::cUser      := AllTrim( cUser )              // [jlalin]
   ::cPassword  := AllTrim( cPassword )          // [jlalin]

   ::oSocket := TSocket():New( nPort )

   ::oSocket:bRead    := {|o,n| ::OnRead( o, n ) }
   ::oSocket:bConnect := {|o,n| ::OnConnect( o, n ) }  // lkm - see adjustment to TSocket class

   // by lkm now you can provide either the IPAddress or the server name (friendly name)
   ::cIPServer := If( IsAlpha( cIPServer ), GetHostByName( AllTrim( cIPServer ) ), cIPServer )
   ::nStatus   := ST_INIT

   // predefined events actions
   ::bDone := {|| MsgInfo( ;
      "Message successfully sent through " + ::cIPServer + CRLF + ;
      GetHostByAddress( ::cIPServer ), MSG_CAPTION ) }
   ::bFailure := {|| ;
      MsgStop( "Session did not complete successfully" + CRLF + CRLF + ::cError, MSG_CAPTION ) }

   ::lTxtAsAttach := .T.                         // force text files as attachments, not inline

return Self
Best Regards,

Gilbert Kuhnert
CTO Software GmbH
http://www.ctosoftware.de
User avatar
gkuhnert
 
Posts: 274
Joined: Fri Apr 04, 2008 1:25 pm
Location: Aachen - Germany // Kerkrade - Netherlands

ein Tip

Postby UD previous posts » Thu Oct 09, 2008 9:52 am

benutz Mailbee

http://www.afterlogic.com/

das rennt bei mir seit 2 Jahren ohne Probleme

kostet 49 Dollar

mfg Uwe D
Using Nissan 350 Z with last Firmware

compiled with Super Plus
UD previous posts
 
Posts: 42
Joined: Sat Sep 30, 2006 9:43 am

Postby gkuhnert » Fri Oct 10, 2008 8:18 am

Uwe,

thanks for your reply. The suggested software seems to be easy in use. But I still hope for a reply on or correction in the fwh own class.
Best Regards,

Gilbert Kuhnert
CTO Software GmbH
http://www.ctosoftware.de
User avatar
gkuhnert
 
Posts: 274
Joined: Fri Apr 04, 2008 1:25 pm
Location: Aachen - Germany // Kerkrade - Netherlands

Postby yury » Fri Oct 10, 2008 7:18 pm

hello Mr.Gilbert,

try with this code in Method New:

Code: Select all  Expand view
METHOD New( cIPServer, nPort, lAuth, cUser, cPassword ) CLASS TSmtp

   Local cIPAlpha:=cIPServer

   Default nPort := 25, ;
           lAuth := .F., ;                       
           cUser := "", ;                       
           cPassword := ""                       

   If Empty( cIPServer )                         
      cIPServer := "0.0.0.0"
   Endif

   ::lAuth      := .F.                           
   ::lDoAuth    := lAuth                         
   ::cUser      := AllTrim( cUser )             
   ::cPassword  := AllTrim( cPassword )         

   ::oSocket := TSocket():New( nPort )

   ::oSocket:bRead    := {|o,n| ::OnRead( o, n ) }
   ::oSocket:bConnect := {|o,n| ::OnConnect( o, n ) }  // lkm - see adjustment to TSocket class

   // by lkm now you can provide either the IPAddress or the server name (friendly name)
   ::cIPServer := If( IsAlpha( cIPServer ), GetHostByName( AllTrim( cIPServer ) ), cIPServer )
   ::cIPServer := If( IsAlpha( cIPAlpha ), GetHostByName( AllTrim( cIPAlpha ) ), cIPAlpha )
   ::nStatus   := ST_INIT

   // predefined events actions
   ::bDone := {|| MsgInfo( ;
      "Message successfully sent through " + ::cIPServer + CRLF + ;
      GetHostByAddress( ::cIPServer ), MSG_CAPTION ) }
   ::bFailure := {|| ;
      MsgStop( "Session did not complete successfully" + CRLF + CRLF + ::cError, MSG_CAPTION ) }

   ::lTxtAsAttach := .T.                         // force text files as attachments, not inline

Return Self


this may sound crazy, but it should be called twice to function gethostbyname () to work

regards
Yury Marcelino Al
yury030575@yahoo.com.br
vimansca@vimansca.com.br
Leme / SP - Brasil
yury
 
Posts: 56
Joined: Wed May 23, 2007 2:01 pm

Postby gkuhnert » Sun Oct 12, 2008 5:47 pm

Yury,

thanks for your input, but it still doesnt work here :-(
When no authentification is required, there are no problems and the blocks bConnected and bDone are evaluated. But with authentification, they both aren't evaluated, but also bFailure doesn't "show up"...
Best Regards,

Gilbert Kuhnert
CTO Software GmbH
http://www.ctosoftware.de
User avatar
gkuhnert
 
Posts: 274
Joined: Fri Apr 04, 2008 1:25 pm
Location: Aachen - Germany // Kerkrade - Netherlands

Postby Rick Lipkin » Sun Oct 12, 2008 8:08 pm

Yury

I just tried your suggested code change to method NEW :

Code: Select all  Expand view
/-----------------------------------------------------------
METHOD New( cIPServer, nPort, lAuth, cUser, cPassword ) CLASS TSmtp

   Local cIPAlpha:=cIPServer

   Default nPort := 25, ;
           lAuth := .F., ;                       
           cUser := "", ;                       
           cPassword := ""                       

   If Empty( cIPServer )                         
      cIPServer := "0.0.0.0"
   Endif

   ::lAuth      := .F.                           
   ::lDoAuth    := lAuth                         
   ::cUser      := AllTrim( cUser )             
   ::cPassword  := AllTrim( cPassword )         

   ::oSocket := TSocket():New( nPort )

   ::oSocket:bRead    := {|o,n| ::OnRead( o, n ) }
   ::oSocket:bConnect := {|o,n| ::OnConnect( o, n ) }  // lkm - see adjustment to TSocket class

   // by lkm now you can provide either the IPAddress or the server name (friendly name)
   ::cIPServer := If( IsAlpha( cIPServer ), GetHostByName( AllTrim( cIPServer ) ), cIPServer )
   ::cIPServer := If( IsAlpha( cIPAlpha ), GetHostByName( AllTrim( cIPAlpha ) ), cIPAlpha )
   ::nStatus   := ST_INIT

   // predefined events actions
   ::bDone := {|| MsgInfo( ;
      "Message successfully sent through " + ::cIPServer + CRLF + ;
      GetHostByAddress( ::cIPServer ), MSG_CAPTION ) }
   ::bFailure := {|| ;
      MsgStop( "Session did not complete successfully" + CRLF + CRLF + ::cError, MSG_CAPTION ) }

   ::lTxtAsAttach := .T.                         // force text files as attachments, not inline

Return Self


where you are adding this line :

Code: Select all  Expand view
Local cIPAlpha:=cIPServer
..
::cIPServer := If( IsAlpha( cIPAlpha ), GetHostByName( AllTrim( cIPAlpha ) ), cIPAlpha )



and from my code ..I sent the lAuth parameter
Code: Select all  Expand view
oWndMdi:SetMsg( "Sending Reporting noticication to "+cTO )

        WSAStartup()
        oOutMail := TSmtp():New( cIP := GetHostByName( cHOST ), 25, .T.,"","" )

        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:bFailure := { | oSocket, nError, cReply | LogFile( "log.txt", { nError, cReply } ), oOutMail:nStatus := 7 }

       oOutMail:bFailure := { | oSocket, nError, cReply | LogFile( "log.txt", { nError, "--", cReply, ProcName( 2 ) } ), oOutMail:nStatus := 7 }

        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


and the log.txt comes back with :

Code: Select all  Expand view
10/12/2008 15:45:28: 0   --   250   TSMTP:ONREAD   


If I remove the second line in NEW ( above ) I get the same line in log.txt ...

Code: Select all  Expand view
10/12/2008 15:56:20: 0   --   250   TSMTP:ONREAD   
10/12/2008 15:56:32: 10048   --      TSMTP:ONCONNECT   


I do seem to concur .. that if you pass the lAuth parameter .. the e-mail is not sent .. go back to just sending the cHOST and leave the other parameters to be picked up in method New .. and the e-mail works once again ..

Sorry for the bad news
Rick
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Postby gkuhnert » Mon Oct 13, 2008 9:32 am

Rick,

thanks for your explanation. But don't be sorry, it's not your fault. I only hope there will be a fix possible soon :)
Best Regards,

Gilbert Kuhnert
CTO Software GmbH
http://www.ctosoftware.de
User avatar
gkuhnert
 
Posts: 274
Joined: Fri Apr 04, 2008 1:25 pm
Location: Aachen - Germany // Kerkrade - Netherlands


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 63 guests