Lianja
Lianja
Route IMAP Through an Existing Ssh Connection
See more IMAP Examples
Demonstrates the Chilkat Imap.UseSsh method, which uses an already connected and authenticated Ssh object as the transport for IMAP connections. The only argument is the Ssh object. Call it before Connect. This example establishes the SSH connection separately, then routes IMAP through it.
Background: SSH supports multiple logical channels over one connection, so a single authenticated
Ssh object can be shared — IMAP, SMTP, and other Chilkat objects can all tunnel through the same SSH session. This differs from SshOpenTunnel, where the Imap object owns and manages the tunnel itself; with UseSsh you manage the Ssh object's lifetime.Chilkat Lianja Downloads
llSuccess = .F.
// Demonstrates the Imap.UseSsh method, which uses an already connected and authenticated Ssh
// object as the transport for IMAP connections. The only argument is the Ssh object. Call it
// before Connect.
loImap = createobject("CkImap")
// Establish and authenticate the SSH connection separately.
loSsh = createobject("CkSsh")
lnSshPort = 22
llSuccess = loSsh.Connect("ssh.example.com",lnSshPort)
if (llSuccess = .F.) then
? loSsh.LastErrorText
release loImap
release loSsh
return
endif
// The SSH password is not hard-coded in source. Insert code here to obtain it from an
// interactive prompt, environment variable, or a secrets vault.
llSuccess = loSsh.AuthenticatePw("sshUser",lcSshPassword)
if (llSuccess = .F.) then
? loSsh.LastErrorText
release loImap
release loSsh
return
endif
// Use the SSH connection as the transport for IMAP. One SSH connection can be shared by
// several Chilkat objects because SSH supports multiple channels.
llSuccess = loImap.UseSsh(loSsh)
if (llSuccess = .F.) then
? loImap.LastErrorText
release loImap
release loSsh
return
endif
// Now connect and log in to the IMAP server through the SSH connection.
loImap.Ssl = .T.
loImap.Port = 993
llSuccess = loImap.Connect("imap.example.com")
if (llSuccess = .F.) then
? loImap.LastErrorText
release loImap
release loSsh
return
endif
llSuccess = loImap.Login("user@example.com","myPassword")
if (llSuccess = .F.) then
? loImap.LastErrorText
release loImap
release loSsh
return
endif
llSuccess = loImap.Disconnect()
if (llSuccess = .F.) then
? loImap.LastErrorText
release loImap
release loSsh
return
endif
release loImap
release loSsh