PowerBuilder
PowerBuilder
Use an Existing Socket SSH Tunnel
See more SMTP Examples
Demonstrates the Chilkat MailMan.UseSshTunnel method, which configures MailMan to use an existing SSH tunnel provided by a Socket object for its SMTP and POP3 connections. This example opens and authenticates a tunnel on a Socket, hands it to MailMan, and then verifies an SMTP login through it.
Background: Sharing one already-established SSH tunnel across objects avoids opening (and authenticating) a separate SSH connection for every component that needs to reach the remote network. Here the tunnel lives on a
Socket object, which MailMan then routes its SMTP/POP3 traffic through. It is the Socket-based sibling of UseSsh, which shares an Ssh object instead.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_SshTunnel
oleobject loo_Mailman
li_Success = 0
// Demonstrates the MailMan.UseSshTunnel method, which configures MailMan to use an existing
// SSH tunnel provided by a Socket object for its SMTP and POP3 connections.
// Open and authenticate the SSH tunnel using a Socket object.
loo_SshTunnel = create oleobject
li_rc = loo_SshTunnel.ConnectToNewObject("Chilkat.Socket")
if li_rc < 0 then
destroy loo_SshTunnel
MessageBox("Error","Connecting to COM object failed")
return
end if
li_Success = loo_SshTunnel.SshOpenTunnel("ssh.example.com",22)
if li_Success = 0 then
Write-Debug loo_SshTunnel.LastErrorText
destroy loo_SshTunnel
return
end if
li_Success = loo_SshTunnel.SshAuthenticatePw("sshUser","sshPassword")
if li_Success = 0 then
Write-Debug loo_SshTunnel.LastErrorText
destroy loo_SshTunnel
return
end if
loo_Mailman = create oleobject
li_rc = loo_Mailman.ConnectToNewObject("Chilkat.MailMan")
// Configure the SMTP server connection. These connections will travel through the tunnel.
loo_Mailman.SmtpHost = "smtp.example.com"
loo_Mailman.SmtpPort = 465
loo_Mailman.SmtpSsl = 1
loo_Mailman.SmtpUsername = "user@example.com"
loo_Mailman.SmtpPassword = "myPassword"
// Tell MailMan to route its connections through the existing tunnel.
li_Success = loo_Mailman.UseSshTunnel(loo_SshTunnel)
if li_Success = 0 then
Write-Debug loo_Mailman.LastErrorText
destroy loo_SshTunnel
destroy loo_Mailman
return
end if
// SMTP operations now travel through the shared SSH tunnel.
li_Success = loo_Mailman.VerifySmtpLogin()
if li_Success = 0 then
Write-Debug loo_Mailman.LastErrorText
destroy loo_SshTunnel
destroy loo_Mailman
return
end if
Write-Debug "Authenticated with the SMTP server through the SSH tunnel."
destroy loo_SshTunnel
destroy loo_Mailman