Sample code for 30+ languages & platforms
PowerBuilder

Open an SSH Tunnel for POP3

See more POP3 Examples

Demonstrates the Chilkat MailMan.SshOpenTunnel method, which connects to an SSH server and opens an SSH tunnel for MailMan's SMTP or POP3 connections. The first argument is the SSH server's hostname or IP address and the second is the SSH port. This example opens a tunnel, authenticates, performs a POP3 operation through it, and closes the tunnel.

Background: An SSH tunnel (port forwarding) wraps another protocol's traffic inside an encrypted SSH connection. Here, MailMan's POP3 or SMTP session is carried through the SSH server rather than connecting directly. This is useful when a mail server is only reachable from inside a network you can reach via SSH, or when policy requires all traffic to traverse a bastion host. Opening the tunnel is step one; you must then authenticate to the SSH server before the tunnel carries traffic.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Mailman
integer li_Count

li_Success = 0

//  Demonstrates the MailMan.SshOpenTunnel method, which connects to an SSH server and opens
//  an SSH tunnel for MailMan's SMTP or POP3 connections.  The 1st argument is the SSH server
//  hostname or IP address, and the 2nd is the SSH port.

loo_Mailman = create oleobject
li_rc = loo_Mailman.ConnectToNewObject("Chilkat.MailMan")
if li_rc < 0 then
    destroy loo_Mailman
    MessageBox("Error","Connecting to COM object failed")
    return
end if

//  Configure the POP3 server connection.  These connections will travel through the tunnel.
loo_Mailman.MailHost = "pop.example.com"
loo_Mailman.MailPort = 995
loo_Mailman.PopSsl = 1
loo_Mailman.PopUsername = "user@example.com"
loo_Mailman.PopPassword = "myPassword"

//  Open the SSH tunnel (port 22 is the standard SSH port).
li_Success = loo_Mailman.SshOpenTunnel("ssh.example.com",22)
if li_Success = 0 then
    Write-Debug loo_Mailman.LastErrorText
    destroy loo_Mailman
    return
end if

//  Authenticate with the SSH server.
li_Success = loo_Mailman.SshAuthenticatePw("sshUser","sshPassword")
if li_Success = 0 then
    Write-Debug loo_Mailman.LastErrorText
    destroy loo_Mailman
    return
end if

//  POP3 operations now travel through the SSH tunnel.
li_Count = loo_Mailman.GetMailboxCount()
if li_Count < 0 then
    Write-Debug "Failed to get the mailbox count."
else
    Write-Debug "Mailbox count: " + string(li_Count)
end if

//  Close the tunnel when finished.
li_Success = loo_Mailman.SshCloseTunnel()
if li_Success = 0 then
    Write-Debug loo_Mailman.LastErrorText
    destroy loo_Mailman
    return
end if



destroy loo_Mailman