Sample code for 30+ languages & platforms
PureBasic Requires Chilkat v11.0.0+

Pass an Email object to the MIME API

See more Email Object Examples

Serialize an Email into a fresh BinData buffer and load those bytes into Mime to inspect the tree. Keep the original file separately when byte-for-byte preservation matters, such as for DKIM verification.

Chilkat PureBasic Downloads

PureBasic
IncludeFile "CkBinData.pb"
IncludeFile "CkMime.pb"
IncludeFile "CkEmail.pb"

Procedure ChilkatExample()

    success.i = 0

    ;  Assumes Chilkat is unlocked. See Global Unlock Sample.

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

    success = CkEmail::ckLoadEml(email,"message.eml")
    If success <> 1
        Debug CkEmail::ckLastErrorText(email)
        CkEmail::ckDispose(email)
        ProcedureReturn
    EndIf

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

    success = CkEmail::ckGetMimeBd(email,mimeBytes)
    If success <> 1
        Debug CkEmail::ckLastErrorText(email)
        CkEmail::ckDispose(email)
        CkBinData::ckDispose(mimeBytes)
        ProcedureReturn
    EndIf

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

    success = CkMime::ckLoadMimeBd(mime,mimeBytes)
    If success <> 1
        Debug CkMime::ckLastErrorText(mime)
        CkEmail::ckDispose(email)
        CkBinData::ckDispose(mimeBytes)
        CkMime::ckDispose(mime)
        ProcedureReturn
    EndIf

    Debug CkMime::ckGetStructure(mime,"text")


    CkEmail::ckDispose(email)
    CkBinData::ckDispose(mimeBytes)
    CkMime::ckDispose(mime)


    ProcedureReturn
EndProcedure