Page 1 of 1

Problem with tsmtp-class

Posted: Thu Oct 09, 2008 7:25 am
by gkuhnert
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

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

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

ein Tip

Posted: Thu Oct 09, 2008 9:52 am
by UD previous posts
benutz Mailbee

http://www.afterlogic.com/

das rennt bei mir seit 2 Jahren ohne Probleme

kostet 49 Dollar

mfg Uwe D

Posted: Fri Oct 10, 2008 8:18 am
by gkuhnert
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.

Posted: Fri Oct 10, 2008 7:18 pm
by yury
hello Mr.Gilbert,

try with this code in Method New:

Code: Select all

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

Posted: Sun Oct 12, 2008 5:47 pm
by gkuhnert
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"...

Posted: Sun Oct 12, 2008 8:08 pm
by Rick Lipkin
Yury

I just tried your suggested code change to method NEW :

Code: Select all

/-----------------------------------------------------------
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

Local cIPAlpha:=cIPServer 
..
::cIPServer := If( IsAlpha( cIPAlpha ), GetHostByName( AllTrim( cIPAlpha ) ), cIPAlpha ) 

and from my code ..I sent the lAuth parameter

Code: Select all

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

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

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

Posted: Mon Oct 13, 2008 9:32 am
by gkuhnert
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 :)