Receber EMAIL com xHabour...

Projeto [x]Harbour - Compilador de código aberto compatível com o Clipper.

Moderador: Moderadores

Shark
Usuário Nível 1
Usuário Nível 1
Mensagens: 28
Registrado em: 25 Set 2017 21:42
Localização: Brasília - DF

Receber EMAIL com xHabour...

Mensagem por Shark »

Algum dos colegas possui rotina que funcione para recebimento de email via código xHarbour / FiveWin ?

Agradeço antecipadamente....
Shark
Usuário Nível 1
Usuário Nível 1
Mensagens: 28
Registrado em: 25 Set 2017 21:42
Localização: Brasília - DF

Receber EMAIL com xHabour...

Mensagem por Shark »

Pesquisei e acabei encontrando um código que funciona pra RECEBER EMAIL COM XHARBOUR / FIVEWIN...

Entretanto, os testes que fiz funcionaram com os emails do meu domínio utilizando POP.
Ainda não testei com google, hotmail e etc. Quem quiser testar e postar aqui o resultado agradeceremos a contribuição.

Segue o código...

Código: Selecionar todos

#include "FiveWin.ch"

STATIC oWnd

//----------------------------------------------------------------------------//

FUNCTION MAIN()

GetMail( "acessosoft.com.br", "autoescola@acessosoft.com.br", "autocfc123" )

DEFINE WINDOW oWnd FROM 1,5 TO 20,75 TITLE "GetMail"

ACTIVATE WINDOW oWnd ON INIT GetMail()

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 +;
                       "Assunto: " + aMail[ i ]:GetFieldPart( "Subject" ) + CRLF +;
                       "De: " + aMail[ i ]:GetFieldPart( "From" ) + CRLF + CRLF +;
                       "Mensagem: " + CRLF + CRLF + aMail[ i ]:GetBody()
            ELSE
                cMsg = "Data: " + aMail[ i ]:GetFieldPart( "Date" ) + CRLF +;
                       "Assunto: " + aMail[ i ]:GetFieldPart( "Subject" ) + CRLF +;
                       "De: " + aMail[ i ]:GetFieldPart( "From" ) + CRLF + CRLF +;
                       "Mensagem: " + CRLF + CRLF + BODY( aPar )
            ENDIF

            WHILE ( oAtt := aMail[ i ]:NextAttachment() ) != NIL

                IF !EMPTY( oAtt:GetFileName() )

                    cMsg += CRLF + "Anexo: " + oAtt:GetFileName()

//                    IF !oAtt:DetachFile(); BREAK; ENDIF
                ENDIF

            ENDDO

            MEMOWRIT( "d:\xemail.txt", 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 )

//----------------------------------------------------------------------------//

Responder