Sample code for 30+ languages & platforms
DataFlex

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

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoImap
    String sTemp1

    Move False To iSuccess

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

    Get Create (RefClass(cComChilkatImap)) To hoImap
    If (Not(IsComObjectCreated(hoImap))) Begin
        Send CreateComObject of hoImap
    End

    Set ComSsl Of hoImap To True
    Set ComPort Of hoImap To 993

    Get ComConnect Of hoImap "imap.example.com" To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoImap To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComLogin Of hoImap "user@example.com" "myPassword" To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoImap To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    //  Create a new mailbox (folder) on the server.
    Get ComCreateMailbox Of hoImap "Archive2026" To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoImap To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Showln "Mailbox created."

    Get ComDisconnect Of hoImap To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoImap To sTemp1
        Showln sTemp1
        Procedure_Return
    End



End_Procedure