Problem with tsmtp-class

Post Reply
User avatar
gkuhnert
Posts: 274
Joined: Fri Apr 04, 2008 1:25 pm
Location: Aachen - Germany // Kerkrade - Netherlands
Contact:

Problem with tsmtp-class

Post 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
Best Regards,

Gilbert Kuhnert
CTO Software GmbH
http://www.ctosoftware.de
UD previous posts
Posts: 42
Joined: Sat Sep 30, 2006 9:43 am

ein Tip

Post 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
Using Nissan 350 Z with last Firmware

compiled with Super Plus
User avatar
gkuhnert
Posts: 274
Joined: Fri Apr 04, 2008 1:25 pm
Location: Aachen - Germany // Kerkrade - Netherlands
Contact:

Post 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.
Best Regards,

Gilbert Kuhnert
CTO Software GmbH
http://www.ctosoftware.de
yury
Posts: 56
Joined: Wed May 23, 2007 2:01 pm

Post 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
Yury Marcelino Al
yury030575@yahoo.com.br
vimansca@vimansca.com.br
Leme / SP - Brasil
User avatar
gkuhnert
Posts: 274
Joined: Fri Apr 04, 2008 1:25 pm
Location: Aachen - Germany // Kerkrade - Netherlands
Contact:

Post 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"...
Best Regards,

Gilbert Kuhnert
CTO Software GmbH
http://www.ctosoftware.de
User avatar
Rick Lipkin
Posts: 2397
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Post 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
User avatar
gkuhnert
Posts: 274
Joined: Fri Apr 04, 2008 1:25 pm
Location: Aachen - Germany // Kerkrade - Netherlands
Contact:

Post 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 :)
Best Regards,

Gilbert Kuhnert
CTO Software GmbH
http://www.ctosoftware.de
Post Reply