Sample code for 30+ languages & platforms
PowerBuilder

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 PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Ssh
oleobject loo_Mailman
integer li_Count

li_Success = 0

//  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.
loo_Ssh = create oleobject
li_rc = loo_Ssh.ConnectToNewObject("Chilkat.Ssh")
if li_rc < 0 then
    destroy loo_Ssh
    MessageBox("Error","Connecting to COM object failed")
    return
end if
li_Success = loo_Ssh.Connect("ssh.example.com",22)
if li_Success = 0 then
    Write-Debug loo_Ssh.LastErrorText
    destroy loo_Ssh
    return
end if

li_Success = loo_Ssh.AuthenticatePw("sshUser","sshPassword")
if li_Success = 0 then
    Write-Debug loo_Ssh.LastErrorText
    destroy loo_Ssh
    return
end if

loo_Mailman = create oleobject
li_rc = loo_Mailman.ConnectToNewObject("Chilkat.MailMan")

//  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"

//  Tell MailMan to route its connections through the already-connected Ssh object.
li_Success = loo_Mailman.UseSsh(loo_Ssh)
if li_Success = 0 then
    Write-Debug loo_Mailman.LastErrorText
    destroy loo_Ssh
    destroy loo_Mailman
    return
end if

//  POP3 operations now travel through the shared SSH connection.
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

loo_Ssh.Disconnect()


destroy loo_Ssh
destroy loo_Mailman