Sample code for 30+ languages & platforms
PureBasic

Upload .eml File to an IMAP Mailbox

See more IMAP Examples

Demonstrates how to upload the MIME source of an email to a mailbox on an IMAP server.

Chilkat PureBasic Downloads

PureBasic
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkImap.pb"

Procedure ChilkatExample()

    success.i = 0

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

    ; This example requires the Chilkat API to have been previously unlocked.
    ; See Global Unlock Sample for sample code.

    ; Connect to an IMAP server.
    ; Use TLS
    CkImap::setCkSsl(imap, 1)
    CkImap::setCkPort(imap, 993)
    success = CkImap::ckConnect(imap,"MY-IMAP-DOMAIN")
    If success <> 1
        Debug CkImap::ckLastErrorText(imap)
        CkImap::ckDispose(imap)
        ProcedureReturn
    EndIf

    ; Login
    success = CkImap::ckLogin(imap,"MY-IMAP-LOGIN","MY-IMAP-PASSWORD")
    If success <> 1
        Debug CkImap::ckLastErrorText(imap)
        CkImap::ckDispose(imap)
        ProcedureReturn
    EndIf

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

    CkStringBuilder::ckLoadFile(sbMime,"qa_data/eml/emoji_pizza.eml","utf-8")

    ; Upload to the mailbox.
    success = CkImap::ckAppendMime(imap,"[Gmail]/testFolder",CkStringBuilder::ckGetAsString(sbMime))
    If success <> 1
        Debug CkImap::ckLastErrorText(imap)
        CkImap::ckDispose(imap)
        CkStringBuilder::ckDispose(sbMime)
        ProcedureReturn
    EndIf

    CkImap::ckDisconnect(imap)

    Debug "OK."


    CkImap::ckDispose(imap)
    CkStringBuilder::ckDispose(sbMime)


    ProcedureReturn
EndProcedure