Sample code for 30+ languages & platforms
PureBasic

Create an IMAP Mailbox

See more IMAP Examples

Demonstrates the Chilkat Imap.CreateMailbox method, which creates a mailbox on the IMAP server. When creating nested mailboxes, use the server's hierarchy delimiter reported in the SeparatorChar property. This example creates a mailbox named Archive2026.

Background: IMAP folders form a hierarchy, and the character that separates levels varies by server — commonly / or .. To create a sub-folder you build the path with that delimiter (for example Archive/2026), which is why you should read SeparatorChar rather than assume one. Creating mailboxes lets an application organize mail into folders programmatically, such as filing messages by year or project.

Chilkat PureBasic Downloads

PureBasic
IncludeFile "CkImap.pb"

Procedure ChilkatExample()

    success.i = 0

    ;  Demonstrates the Imap.CreateMailbox method, which creates a mailbox on the IMAP server.
    ;  Use the server's hierarchy delimiter (the SeparatorChar property) when creating nested
    ;  mailboxes.

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

    CkImap::setCkSsl(imap, 1)
    CkImap::setCkPort(imap, 993)

    success = CkImap::ckConnect(imap,"imap.example.com")
    If success = 0
        Debug CkImap::ckLastErrorText(imap)
        CkImap::ckDispose(imap)
        ProcedureReturn
    EndIf

    success = CkImap::ckLogin(imap,"user@example.com","myPassword")
    If success = 0
        Debug CkImap::ckLastErrorText(imap)
        CkImap::ckDispose(imap)
        ProcedureReturn
    EndIf

    ;  Create a new mailbox (folder) on the server.
    success = CkImap::ckCreateMailbox(imap,"Archive2026")
    If success = 0
        Debug CkImap::ckLastErrorText(imap)
        CkImap::ckDispose(imap)
        ProcedureReturn
    EndIf

    Debug "Mailbox created."

    success = CkImap::ckDisconnect(imap)
    If success = 0
        Debug CkImap::ckLastErrorText(imap)
        CkImap::ckDispose(imap)
        ProcedureReturn
    EndIf



    CkImap::ckDispose(imap)


    ProcedureReturn
EndProcedure