Sample code for 30+ languages & platforms
PowerBuilder

Close the SSH Tunnel

See more POP3 Examples

Demonstrates the Chilkat MailMan.SshCloseTunnel method, which closes the SSH tunnel used for SMTP or POP3 communication. This example opens and authenticates a tunnel, performs a mail operation through it, and then closes it.

Background: An SSH tunnel holds an open connection to the SSH server for as long as it is needed, so closing it releases both that connection and the resources on the SSH server. The natural pattern is open → authenticate → do mail work → close. It is the counterpart to SshOpenTunnel, and is separate from closing the mail connections themselves (CloseSmtpConnection / Pop3EndSession), which ride inside the tunnel.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Mailman
integer li_Count

li_Success = 0

//  Demonstrates the MailMan.SshCloseTunnel method, which closes the SSH tunnel used for SMTP
//  or POP3 communication.

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.
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 and authenticate the SSH tunnel.
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

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

//  ... perform mail operations through the 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 SSH tunnel when finished with it.
li_Success = loo_Mailman.SshCloseTunnel()
if li_Success = 0 then
    Write-Debug loo_Mailman.LastErrorText
    destroy loo_Mailman
    return
end if

Write-Debug "SSH tunnel closed."


destroy loo_Mailman