PowerBuilder
PowerBuilder
Authenticate an SSH Tunnel with a Password
See more SMTP Examples
Demonstrates the Chilkat MailMan.SshAuthenticatePw method, which authenticates with the SSH server using an SSH username and password after an SSH tunnel has been opened. The first argument is the SSH account name and the second is the corresponding password. This example opens a tunnel, authenticates, and sends SMTP traffic through it.
Background: Opening an SSH tunnel and authenticating to the SSH server are two separate steps, and note the SSH credentials are distinct from the mail account credentials — the SSH login gets you through the tunnel, while
SmtpUsername/SmtpPassword authenticate to the mail server at the far end. Password authentication is the simplest option; public-key authentication (SshAuthenticatePk) is generally preferred for automated systems.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Mailman
li_Success = 0
// Demonstrates the MailMan.SshAuthenticatePw method, which authenticates with the SSH server
// using an SSH username and password after an SSH tunnel has been opened. The 1st argument
// is the SSH account name and the 2nd is the corresponding password.
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 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"
// Open the SSH tunnel first.
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 using a username and password.
li_Success = loo_Mailman.SshAuthenticatePw("sshUser","sshPassword")
if li_Success = 0 then
Write-Debug loo_Mailman.LastErrorText
destroy loo_Mailman
return
end if
Write-Debug "SSH tunnel authenticated."
// SMTP operations now travel through the SSH tunnel.
li_Success = loo_Mailman.VerifySmtpLogin()
if li_Success = 0 then
Write-Debug loo_Mailman.LastErrorText
destroy loo_Mailman
return
end if
li_Success = loo_Mailman.SshCloseTunnel()
if li_Success = 0 then
Write-Debug loo_Mailman.LastErrorText
destroy loo_Mailman
return
end if
destroy loo_Mailman