Sample code for 30+ languages & platforms
DataFlex

Connect to an IMAP Server

See more IMAP Examples

Demonstrates the Chilkat Imap.Connect method, which establishes a TCP connection to the IMAP server but does not authenticate. The argument may be a hostname, IPv4, or IPv6 address; configure Ssl and Port first. This example connects with implicit TLS, then logs in and disconnects.

Background: IMAP (Internet Message Access Protocol) is the protocol for accessing mail that stays on the server — unlike POP3, which typically downloads and removes it. That server-side model is what lets multiple devices see the same mailboxes, folders, and read/unread state. A session starts by connecting (usually implicit TLS on port 993), then authenticating — Connect performs only the first step, so it is always followed by Login.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoImap
    String sTemp1

    Move False To iSuccess

    //  Demonstrates the Imap.Connect method, which establishes a TCP connection to the IMAP
    //  server but does not authenticate.  Call Login after connecting to authenticate.

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

    //  Use implicit TLS on the standard IMAPS port.
    Set ComSsl Of hoImap To True
    Set ComPort Of hoImap To 993

    //  Establish the connection to the IMAP server (no authentication yet).
    Get ComConnect Of hoImap "imap.example.com" To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoImap To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Showln "Connected to the IMAP server."

    //  Authenticate the session.
    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

    //  Disconnect when finished.
    Get ComDisconnect Of hoImap To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoImap To sTemp1
        Showln sTemp1
        Procedure_Return
    End



End_Procedure