FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour How to receive an e-mail message with xharbou / fivewin
Posts: 55
Joined: Thu Mar 13, 2008 02:35 AM
How to receive an e-mail message with xharbou / fivewin
Posted: Wed May 23, 2018 01:49 AM

Does anyone have a routine to receive email that works?

Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: How to receive an e-mail message with xharbou / fivewin
Posted: Wed May 23, 2018 08:16 AM
Here it is:

Code (fw): Select all Collapse
#include "Fivewin.ch"


FUNCTION MAIN()

    ? GETMAIL( "server", "userid", "password" )

    RETURN NIL


STATIC FUNCTION GETMAIL( cServer, cUser, cPassword )

    LOCAL lOk := .F.

    LOCAL oCli

    LOCAL aMail, aPar, cMsg, oAtt

    LOCAL i

    TRY
        oCli = TIPClientPOP():New( "pop://" + STRTRAN( cUser, "@", "&at;" ) + ":" + cPassword + "@" + cServer )

        IF EMPTY( oCli ); BREAK; ENDIF

        oCli:oUrl:cUserid = cUser

        IF !oCli:Open(); BREAK; ENDIF

        aMail = oCli:RetrieveAll()

        FOR i = 1 TO LEN( aMail ) - 1
            aPar = aMail[ i ]:GetMultiParts()

            IF LEN( aPar ) = 0
                cMsg = "Data: " + aMail[ i ]:GetFieldPart( "Date" ) + CRLF +;
                       "Oggetto: " + aMail[ i ]:GetFieldPart( "Subject" ) + CRLF +;
                       "Mittente: " + aMail[ i ]:GetFieldPart( "From" ) + CRLF + CRLF +;
                       "Messaggio: " + CRLF + CRLF + aMail[ i ]:GetBody()
            ELSE
                cMsg = "Data: " + aMail[ i ]:GetFieldPart( "Date" ) + CRLF +;
                       "Oggetto: " + aMail[ i ]:GetFieldPart( "Subject" ) + CRLF +;
                       "Mittente: " + aMail[ i ]:GetFieldPart( "From" ) + CRLF + CRLF +;
                       "Messaggio: " + CRLF + CRLF + BODY( aPar )
            ENDIF

            WHILE ( oAtt := aMail[ i ]:NextAttachment() ) != NIL
                IF !EMPTY( oAtt:GetFileName() )
                    cMsg += CRLF + "Allegato: " + oAtt:GetFileName()
//                    IF !oAtt:DetachFile(); BREAK; ENDIF
                ENDIF
            ENDDO

            ? cMsg
        NEXT

        lOk = .T.
    CATCH
    END

    IF !EMPTY( oCli ); oCli:Close(); ENDIF

    RETURN lOk


STATIC FUNCTION BODY( aPar )

    LOCAL cMsg := ""

    LOCAL i

    FOR i = 1 TO LEN( aPar )
        IF EMPTY( aPar[ i ]:GetFieldPart( "Content-Disposition" ) )
            cMsg += aPar[ i ]:GetBody()
        ENDIF
    NEXT

    RETURN ALLTRIM( cMsg )


EMG
Posts: 55
Joined: Thu Mar 13, 2008 02:35 AM
Re: How to receive an e-mail message with xharbou / fivewin
Posted: Wed May 23, 2018 06:55 PM

Thanks Enrico.

post an string example of cserver, cuser and cpass fill...

I do not know how to fill this variables.

Continue the discussion