Sample code for 30+ languages & platforms
Classic ASP

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 Classic ASP Downloads

Classic ASP
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
success = 0

'  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.

set imap = Server.CreateObject("Chilkat.Imap")

'  Establish and authenticate the SSH connection separately.
set ssh = Server.CreateObject("Chilkat.Ssh")
sshPort = 22
success = ssh.Connect("ssh.example.com",sshPort)
If (success = 0) Then
    Response.Write "<pre>" & Server.HTMLEncode( ssh.LastErrorText) & "</pre>"
    Response.End
End If

'  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.

success = ssh.AuthenticatePw("sshUser",sshPassword)
If (success = 0) Then
    Response.Write "<pre>" & Server.HTMLEncode( ssh.LastErrorText) & "</pre>"
    Response.End
End If

'  Use the SSH connection as the transport for IMAP.  One SSH connection can be shared by
'  several Chilkat objects because SSH supports multiple channels.
success = imap.UseSsh(ssh)
If (success = 0) Then
    Response.Write "<pre>" & Server.HTMLEncode( imap.LastErrorText) & "</pre>"
    Response.End
End If

'  Now connect and log in to the IMAP server through the SSH connection.
imap.Ssl = 1
imap.Port = 993
success = imap.Connect("imap.example.com")
If (success = 0) Then
    Response.Write "<pre>" & Server.HTMLEncode( imap.LastErrorText) & "</pre>"
    Response.End
End If

success = imap.Login("user@example.com","myPassword")
If (success = 0) Then
    Response.Write "<pre>" & Server.HTMLEncode( imap.LastErrorText) & "</pre>"
    Response.End
End If

success = imap.Disconnect()
If (success = 0) Then
    Response.Write "<pre>" & Server.HTMLEncode( imap.LastErrorText) & "</pre>"
    Response.End
End If


%>
</body>
</html>