Sample code for 30+ languages & platforms
DataFlex

Check the Last Known IMAP Connection State

See more IMAP Examples

Demonstrates the Chilkat Imap.IsConnected method, which returns the last known connection state without sending any data to the IMAP server. A true result does not prove that an idle connection is still usable. This example connects and reads the state.

Background: IsConnected is a cheap, cached check — it reports what Chilkat last observed without touching the network. That makes it fast, but it can be stale: a server or firewall may have silently dropped an idle connection. When you need to be sure the connection is actually alive, send a lightweight round trip such as Noop, or use CheckConnection for a low-level socket probe.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoImap
    Boolean iConnected
    String sTemp1

    Move False To iSuccess

    //  Demonstrates the Imap.IsConnected method, which returns the last known connection state
    //  without sending data to the IMAP server.  A true result does not prove that an idle
    //  connection is still usable.

    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

    //  Check the last known connection state (no data is sent to the server).
    Get ComIsConnected Of hoImap To iConnected
    If (iConnected = True) Begin
        Showln "The IMAP object believes it is connected."
    End
    Else Begin
        Showln "The IMAP object is not connected."
    End

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



End_Procedure