FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour SMTP Fails FWH 9.12 / xHarbour Nov 09
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
SMTP Fails FWH 9.12 / xHarbour Nov 09
Posted: Fri Feb 26, 2010 02:31 AM
I have had a working email SMTP program without problems using FWH 9.5 and xHarbour May 09.

Now the same code does not go through. I am using FWH 9.12 and xHarbour main release of November 2009 ( xHarbour.com with xBuilder ). The following code can be compiled/linked as a standalone. The server info is accurate and can be used for testing. Feel free to build it and send it.
It is not just with this server. I have the same problem with my local server using Port 25. I'm obviously overlooking something.

Your input would be greatly appreciated.

Code (fw): Select all Collapse
#include "fivewin.ch" //
#INCLUDE "wcolors.CH"
#include "common.ch"

#DEFINE HELP_FINDER
#DEFINE HKEY_LOCAL_MACHINE      2147483650
#DEFINE INTERNET_FLAG_PASSIVE   0x08000000



PROCEDURE main

    LOCAL cSndTo := "TimStone@masterlinksoftware.com"
    LOCAL SndFile := ""
    LOCAL cSubj := "Test of email system"
    LOCAL cText := "It would be nice for this to work."
    PRIVATE oWnd

        DEFINE WINDOW oWnd TITLE "Test ASW Email" FROM 0,0 TO 400, 600 PIXEL

        SET MESSAGE OF oWnd TO " " 2007 NOINSET DATE KEYBOARD

        ACTIVATE WINDOW oWnd ON INIT    ASWSend( cSndTo, SndFile, cText, cSubj )

RETURN NIL




FUNCTION ASWSend( MailTo, cSndFile, cText, cSubj )

    // Declare LOCAL variables
    LOCAL oInit, oMail
    LOCAL mailname, mailself, mailuser, mailpass, mailport, lreceipt := .F., lUseMLS := .F.
    LOCAL cFrom

    // Open Config File and get email setup information
    mailname := "mail.masterlinksoftware.com"
    mailself := "timstone@masterlinksoftware.com"
    mailuser := "c10000@masterlinksoftware.com"
    mailpass := "drmls82"
    mailport := 587
    mailauth := .T.
    cSender := ALLTRIM( mailuser )
    cHost := ALLTRIM( mailname )
    cMailTo := ALLTRIM( MailTo )
    aFiles := { cSndFile }

    // initialize sockets (or nothing will happen) - it's a quirk in GetHostByName(), not TSmtp
    oInit := TSmtp():New( cHost, mailport, mailauth , mailuser, mailpass )
    // now let's go for our socket
    oMail := TSmtp():New( cHost, mailport, mailauth , mailuser, mailpass )

    oMail:cReplyTo := mailself
    oMail:nGMT := -8 // Pacific Standard Time (GMT -08:00) - Adjust this to your own Time Zone!

    // Provide for a delay
    oMail:nDelay := 2

    // Create a log file
    oMail:oSocket:lDebug := .T.
    oMail:oSocket:cLogFile := "smtp.log"

    // Now connect to host
    oMail:bConnecting := {|| oWnd:SetMsg( "Connecting to " + cHost + " (" + oMail:cIPServer + ;
        ") and waiting for response..." ) }
    oMail:bConnected := {|| oWnd:SetMsg( "Connected and sending mail and attachments..." ) }
    oMail:bDone := { || oWnd:SetMsg( "Message sent successfully" ) }
    oMail:bFailure := { || oMail:nStatus := 7 }

    // Complete message and send
    cMsg := "Thank You"
    oMail:SendMail( cSender, { cMailTo }, cText, cSubj, aFiles, {}, {}, .F. , NIL )

    oInit:end()
    IF oMail <> nil
        oMail:End()
    ENDIF

    MsgInfo( "Finished" )

RETURN NIL
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: SMTP Fails FWH 9.12 / xHarbour Nov 09
Posted: Fri Feb 26, 2010 07:33 PM

Tim,

Do you get the "finished" msg ?

We get the MsgInfo( "finished" ) properly shown

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: SMTP Fails FWH 9.12 / xHarbour Nov 09
Posted: Fri Feb 26, 2010 07:48 PM

Yes, but it doesn't actually send the emails. On the MsgBar I get only the message that it is attempting to connect.

The frustration is that the exact same code worked in the earlier FWH 9.05 and xHarbour (.com) May 2009.

Also, I am not getting an smtp.log file ... which would help.

Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: SMTP Fails FWH 9.12 / xHarbour Nov 09
Posted: Fri Feb 26, 2010 11:38 PM
Tim,

There is a fix required for winsock.c in these lines: ("v" is missing in ...stor... calls)
Code (fw): Select all Collapse
   if( wLen < 10000 )  // socket errors = 10000 + ...
      hb_storvclen( ( char * ) buffer, wLen, 2 );
   else
      hb_storvclen( "", 0, 2 );

once that code is changed, if you remove this line in your example:
Code (fw): Select all Collapse
    // oInit := TSmtp():New( cHost, mailport, mailauth , mailuser, mailpass )

then the log file is generated and I get this:
Code (fw): Select all Collapse
02/27/10 00:32:46: Connect  Socket handle:       240    
02/27/10 00:32:46: Write    Socket handle:       240    
02/27/10 00:32:48: Read Socket handle:       240    
02/27/10 00:32:48: 220-phoenix.lunarpages.com ESMTP Exim 4.69 #1 Fri, 26 Feb 2010 15:32:47 -0800 
220-We do not authorize the use of this system to transport unsolicited, 
220 and/or bulk e-mail.
    
02/27/10 00:32:48: Read Socket handle:       240    
02/27/10 00:32:48: 250 phoenix.lunarpages.com Hello 253.199.222.87.dynamic.jazztel.es [87.222.198.242]
    
02/27/10 00:32:49: Read Socket handle:       240    
02/27/10 00:32:49: 503 AUTH command used when not advertised
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: SMTP Fails FWH 9.12 / xHarbour Nov 09
Posted: Sat Feb 27, 2010 12:54 AM

I'm using xHarbour Builder and having a problem building Winsock.c

Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 PM
Re: SMTP Fails FWH 9.12 / xHarbour Nov 09
Posted: Sat Feb 27, 2010 01:05 AM
Tim...

maybe you need the prototypes to xharbour, you can copy at the end your main prg

this code was got from fwh\source\function\harbour.prg

Code (fw): Select all Collapse
#ifdef __XHARBOUR__

// Keep this C code here so only xHarbour uses it

#pragma BEGINDUMP

//char * hb_parc( int iParam, ... );
//ULONG  hb_parclen( int iParam, ... );
//int    hb_parni( int iParam, ... );
//LONG   hb_parnl( int iParam, ... );
//int    hb_parl( int iParam, ... );
//void   hb_storc( const char * szText, int iParam, ... );
//void   hb_storclen( const char * szText, ULONG ulLength, int iParam, ... );
//void   hb_storl( int iLogical, int iParam, ... );
//void   hb_storni( int iValue, int iParam, ... );
//void   hb_stornl( LONG lValue, int iParam, ... ); 
//void   hb_stords( const char * szDate, int iParam, ... );
//void   hb_stornd( double dValue, int iParam, ... );

char * hb_parvc( int iParam, int iIndex )
{
   return ( char * ) hb_parc( iParam, iIndex );
}   

ULONG hb_parvclen( int iParam, int iIndex )
{
   return hb_parclen( iParam, iIndex );
} 

int hb_parvni( int iParam, int iIndex )
{
   return hb_parni( iParam, iIndex );
}  

long hb_parvnl( int iParam, int iIndex )
{
   return hb_parnl( iParam, iIndex );
}  

BOOL hb_parvl( int iParam, int iIndex )
{
   return hb_parl( iParam, iIndex );
}  

void hb_storvc( char * szText, int iParam, int iIndex )
{
   hb_storc( szText, iParam, iIndex );
}   

void hb_storvclen( char * szText, ULONG ulLength, int iParam )
{
   hb_storclen( szText, ulLength, iParam );
}   

void hb_storvl( BOOL bValue, int iParam, int iIndex )
{
   hb_storl( bValue, iParam, iIndex );
}   

void hb_storvnl( LONG lValue, int iParam, int iIndex )
{
   hb_stornl( lValue, iParam, iIndex );
}  

void hb_storvni( int iValue, int iParam, int iIndex )
{
   hb_storni( iValue, iParam, iIndex );
} 

void hb_storvds( char * szDate, int iParam, int iIndex )
{
   hb_stords( szDate, iParam, iIndex );
}     

void hb_storvnd( double dValue, int iParam, int iIndex )
{
   hb_stornd( dValue, iParam, iIndex );
}     

#pragma ENDDUMP

#endif
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: SMTP Fails FWH 9.12 / xHarbour Nov 09
Posted: Sat Feb 27, 2010 02:37 AM

Sorry but I'm just getting more of a mess ....

I need the corrected winsock.obj file ....

Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: SMTP Fails FWH 9.12 / xHarbour Nov 09
Posted: Sun Feb 28, 2010 10:22 AM

Tim,

I already emailed you the OBJ. What was the result ?

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: SMTP Fails FWH 9.12 / xHarbour Nov 09
Posted: Mon Mar 01, 2010 03:08 PM

It is still not working for me. No log, no transmission.

Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: SMTP Fails FWH 9.12 / xHarbour Nov 09
Posted: Mon Mar 01, 2010 05:43 PM

Tim,

Have you removed this line ?

// oInit := TSmtp():New( cHost, mailport, mailauth , mailuser, mailpass )

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: SMTP Fails FWH 9.12 / xHarbour Nov 09
Posted: Mon Mar 01, 2010 05:51 PM

Yes

Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
Posts: 1048
Joined: Mon Oct 24, 2005 09:54 AM
Re: SMTP Fails FWH 9.12 / xHarbour Nov 09
Posted: Tue Mar 02, 2010 04:38 PM

Now I also test SMTP with xharbour and 9.08. I found, that the mails are going out, but the messages "connected" and "sent" are not shown. In harbour and 9.08 all is ok! Without oInit in both cases no mails are sent!!
Antonio, any solution?

Regards,
Günther
---------------------------------
office@byte-one.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: SMTP Fails FWH 9.12 / xHarbour Nov 09
Posted: Tue Mar 02, 2010 05:37 PM

Günther,

What SMTP example are you using ? FWH\samples\TestSmtp.prg ?

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: SMTP Fails FWH 9.12 / xHarbour Nov 09
Posted: Tue Mar 02, 2010 05:44 PM

FWH\samples\TestSmtp.prg is working fine with both Harbour and xHarbour and FWH 10.2

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1048
Joined: Mon Oct 24, 2005 09:54 AM
Re: SMTP Fails FWH 9.12 / xHarbour Nov 09
Posted: Tue Mar 02, 2010 06:14 PM

Antonio, you use in the example:
oOutMail:bConnected = { || oWnd:SetMsg( "Connected" ) }

and i use:
oOutMail:bConnected = { || (cV := "Connected", oSay:refresh()) }
where cV is the variable from the say-object

Regards,
Günther
---------------------------------
office@byte-one.com

Continue the discussion