Sample code for 30+ languages & platforms
DataFlex

Subscribe to an IMAP Mailbox

See more IMAP Examples

Demonstrates the Chilkat Imap.Subscribe method, which subscribes the authenticated IMAP account to a mailbox. Subscription controls which mailboxes are returned by subscribed-mailbox listings. This example subscribes to a mailbox.

Background: An account can have many mailboxes, but a user often cares about only some of them. IMAP's subscription list is that curated set: mail clients typically show subscribed folders by default and hide the rest. Subscribing does not create or change a mailbox — it only adds it to the "show me this one" list (retrieved with a subscribed-only listing). Unsubscribe removes it from that list.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoImap
    String sTemp1

    Move False To iSuccess

    //  Demonstrates the Imap.Subscribe method, which subscribes the authenticated IMAP account to
    //  a mailbox.  Subscription controls which mailboxes are returned by subscribed-mailbox
    //  listings.

    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

    //  Subscribe to a mailbox.
    Get ComSubscribe Of hoImap "Archive2026" To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoImap To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Showln "Subscribed to the mailbox."

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



End_Procedure