Sample code for 30+ languages & platforms
DataFlex

Use an Existing Ssh Object as the Tunnel

See more POP3 Examples

Demonstrates the Chilkat MailMan.UseSsh method, which configures MailMan to use an existing SSH tunnel provided by an Ssh object for its SMTP and POP3 connections. This example connects and authenticates an Ssh object separately, hands it to MailMan, and then performs a POP3 operation through it.

Background: Rather than having MailMan open its own tunnel (SshOpenTunnel), you can manage the SSH connection yourself and share it. That is valuable when several Chilkat objects must reach the same remote network — they all ride one authenticated SSH connection instead of each opening its own — and it enables advanced setups such as multi-hop SSH, where the Ssh object is already chained through intermediate servers.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Variant vSsh
    Handle hoSsh
    Handle hoMailman
    Integer iCount
    String sTemp1

    Move False To iSuccess

    //  Demonstrates the MailMan.UseSsh method, which configures MailMan to use an existing SSH
    //  tunnel provided by an Ssh object for its SMTP and POP3 connections.

    //  Establish the SSH connection separately, using an Ssh object.
    Get Create (RefClass(cComChilkatSsh)) To hoSsh
    If (Not(IsComObjectCreated(hoSsh))) Begin
        Send CreateComObject of hoSsh
    End
    Get ComConnect Of hoSsh "ssh.example.com" 22 To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoSsh To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComAuthenticatePw Of hoSsh "sshUser" "sshPassword" To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoSsh To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatMailMan)) To hoMailman
    If (Not(IsComObjectCreated(hoMailman))) Begin
        Send CreateComObject of hoMailman
    End

    //  Configure the POP3 server connection.  These connections will travel through the tunnel.
    Set ComMailHost Of hoMailman To "pop.example.com"
    Set ComMailPort Of hoMailman To 995
    Set ComPopSsl Of hoMailman To True
    Set ComPopUsername Of hoMailman To "user@example.com"
    Set ComPopPassword Of hoMailman To "myPassword"

    //  Tell MailMan to route its connections through the already-connected Ssh object.
    Get pvComObject of hoSsh to vSsh
    Get ComUseSsh Of hoMailman vSsh To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoMailman To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    //  POP3 operations now travel through the shared SSH connection.
    Get ComGetMailboxCount Of hoMailman To iCount
    If (iCount < 0) Begin
        Showln "Failed to get the mailbox count."
    End
    Else Begin
        Showln "Mailbox count: " iCount
    End

    Send ComDisconnect To hoSsh


End_Procedure