Visual Basic 6.0
Visual Basic 6.0
Share an Existing SSH Tunnel (Socket) with IMAP
See more IMAP Examples
Demonstrates the Chilkat Imap.UseSshTunnel method, which uses an existing SSH tunnel, represented by a Socket object, for IMAP connections. The only argument is the Socket. Call it before Connect. This example opens and authenticates the tunnel on a Socket, then routes IMAP through it.
Background: A
Socket object can open and hold an SSH tunnel that several Chilkat objects share. This is the approach when the tunnel is managed independently of any one protocol object — for example a long-lived tunnel reused across IMAP, POP3, and SMTP sessions — whereas SshOpenTunnel ties the tunnel's lifetime to the Imap object.Chilkat Visual Basic 6.0 Downloads
Dim success As Long
success = 0
' Demonstrates the Imap.UseSshTunnel method, which uses an existing SSH tunnel (represented by
' a Socket) for IMAP connections. The only argument is the Socket. Call it before Connect.
Dim imap As New ChilkatImap
' Open and authenticate an SSH tunnel on a Socket object. This tunnel can be shared with
' other Chilkat objects.
Dim sshTunnel As New ChilkatSocket
Dim sshPort As Long
sshPort = 22
success = sshTunnel.SshOpenTunnel("ssh.example.com",sshPort)
If (success = 0) Then
Debug.Print sshTunnel.LastErrorText
Exit Sub
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.
Dim sshPassword As String
success = sshTunnel.SshAuthenticatePw("sshUser",sshPassword)
If (success = 0) Then
Debug.Print sshTunnel.LastErrorText
Exit Sub
End If
' Tell the Imap object to use the existing tunnel.
success = imap.UseSshTunnel(sshTunnel)
If (success = 0) Then
Debug.Print imap.LastErrorText
Exit Sub
End If
' Now connect and log in to the IMAP server through the tunnel.
imap.Ssl = 1
imap.Port = 993
success = imap.Connect("imap.example.com")
If (success = 0) Then
Debug.Print imap.LastErrorText
Exit Sub
End If
success = imap.Login("user@example.com","myPassword")
If (success = 0) Then
Debug.Print imap.LastErrorText
Exit Sub
End If
success = imap.Disconnect()
If (success = 0) Then
Debug.Print imap.LastErrorText
Exit Sub
End If