How to receive an e-mail message with xharbou / fivewin

How to receive an e-mail message with xharbou / fivewin

Postby shark » Wed May 23, 2018 1:49 am

Does anyone have a routine to receive email that works?
shark
 
Posts: 55
Joined: Thu Mar 13, 2008 2:35 am

Re: How to receive an e-mail message with xharbou / fivewin

Postby Enrico Maria Giordano » Wed May 23, 2018 8:16 am

Here it is:

Code: Select all  Expand view
#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
User avatar
Enrico Maria Giordano
 
Posts: 8713
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: How to receive an e-mail message with xharbou / fivewin

Postby shark » Wed May 23, 2018 6:55 pm

Thanks Enrico.

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

I do not know how to fill this variables.
shark
 
Posts: 55
Joined: Thu Mar 13, 2008 2:35 am


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 84 guests