Sample code for 30+ languages & platforms
PureBasic

Fetch a POP3 Message's Raw MIME by UIDL

See more POP3 Examples

Demonstrates the Chilkat MailMan.FetchMimeBd method, which fetches an email from the POP3 server by UIDL and stores the raw MIME source bytes in a BinData. Chilkat clears the BinData before downloading. This example fetches one message's MIME into a BinData.

Background: Sometimes you want the message exactly as it arrived — the raw MIME bytes — rather than a parsed Email object, for example to archive it verbatim as a .eml file, forward it untouched, or hash it. Fetching into a BinData preserves every byte precisely, without any parsing or re-encoding that could alter the original.

Chilkat PureBasic Downloads

PureBasic
IncludeFile "CkBinData.pb"
IncludeFile "CkMailMan.pb"

Procedure ChilkatExample()

    success.i = 0

    ;  Demonstrates the MailMan.FetchMimeBd method, which fetches an email from the POP3 server
    ;  by UIDL and stores the raw MIME source bytes in a BinData.  Chilkat clears the BinData
    ;  before downloading.

    mailman.i = CkMailMan::ckCreate()
    If mailman.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    ;  Configure the POP3 server connection.
    CkMailMan::setCkMailHost(mailman, "pop.example.com")
    CkMailMan::setCkMailPort(mailman, 995)
    CkMailMan::setCkPopSsl(mailman, 1)
    CkMailMan::setCkPopUsername(mailman, "user@example.com")
    CkMailMan::setCkPopPassword(mailman, "myPassword")

    ;  Fetch the raw MIME of a specific message by UIDL into a BinData.
    bdMime.i = CkBinData::ckCreate()
    If bdMime.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success = CkMailMan::ckFetchMimeBd(mailman,"0000000123abcdef",bdMime)
    If success = 0
        Debug CkMailMan::ckLastErrorText(mailman)
        CkMailMan::ckDispose(mailman)
        CkBinData::ckDispose(bdMime)
        ProcedureReturn
    EndIf

    Debug "MIME size (bytes) = " + Str(CkBinData::ckNumBytes(bdMime))

    ;  Note: Explicitly connecting/authenticating is optional.  Chilkat MailMan automatically
    ;  connects and authenticates -- using the property settings above -- whenever a server
    ;  operation requires it.  Calling the explicit connect/authenticate methods can still be
    ;  helpful to determine whether a failure occurs while connecting or while authenticating.


    CkMailMan::ckDispose(mailman)
    CkBinData::ckDispose(bdMime)


    ProcedureReturn
EndProcedure