Sample code for 30+ languages & platforms
DataFlex

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 DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoMailman
    Variant vBdMime
    Handle hoBdMime
    String sTemp1
    Integer iTemp1

    Move False To iSuccess

    //  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.

    Get Create (RefClass(cComChilkatMailMan)) To hoMailman
    If (Not(IsComObjectCreated(hoMailman))) Begin
        Send CreateComObject of hoMailman
    End

    //  Configure the POP3 server connection.
    Set ComMailHost Of hoMailman To "pop.example.com"
    Set ComMailPort Of hoMailman To 995
    Set ComPopSsl Of hoMailman To True
    Set ComPopUsername Of hoMailman To "user@example.com"
    Set ComPopPassword Of hoMailman To "myPassword"

    //  Fetch the raw MIME of a specific message by UIDL into a BinData.
    Get Create (RefClass(cComChilkatBinData)) To hoBdMime
    If (Not(IsComObjectCreated(hoBdMime))) Begin
        Send CreateComObject of hoBdMime
    End

    Get pvComObject of hoBdMime to vBdMime
    Get ComFetchMimeBd Of hoMailman "0000000123abcdef" vBdMime To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoMailman To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComNumBytes Of hoBdMime To iTemp1
    Showln "MIME size (bytes) = " iTemp1

    //  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.


End_Procedure