FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Problem with tsmtp-class
Posts: 274
Joined: Fri Apr 04, 2008 01:25 PM
Problem with tsmtp-class
Posted: Thu Oct 09, 2008 07: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):

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:

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
Posts: 42
Joined: Sat Sep 30, 2006 09:43 AM
ein Tip
Posted: Thu Oct 09, 2008 09: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
Posts: 274
Joined: Fri Apr 04, 2008 01:25 PM
Problem with tsmtp-class
Posted: Fri Oct 10, 2008 08: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
Posts: 56
Joined: Wed May 23, 2007 02:01 PM
Problem with tsmtp-class
Posted: Fri Oct 10, 2008 07:18 PM
hello Mr.Gilbert,

try with this code in Method New:

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
Posts: 274
Joined: Fri Apr 04, 2008 01:25 PM
Problem with tsmtp-class
Posted: Sun Oct 12, 2008 05: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
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Problem with tsmtp-class
Posted: Sun Oct 12, 2008 08:08 PM
Yury

I just tried your suggested code change to method NEW :

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

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



and from my code ..I sent the lAuth parameter
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 :

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

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
Posts: 274
Joined: Fri Apr 04, 2008 01:25 PM
Problem with tsmtp-class
Posted: Mon Oct 13, 2008 09: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

Continue the discussion