DataFlex
DataFlex
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 DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Variant vSshTunnel
Handle hoSshTunnel
Handle hoMailman
String sTemp1
Move False To iSuccess
// 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.
Get Create (RefClass(cComChilkatSocket)) To hoSshTunnel
If (Not(IsComObjectCreated(hoSshTunnel))) Begin
Send CreateComObject of hoSshTunnel
End
Get ComSshOpenTunnel Of hoSshTunnel "ssh.example.com" 22 To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoSshTunnel To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComSshAuthenticatePw Of hoSshTunnel "sshUser" "sshPassword" To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoSshTunnel To sTemp1
Showln sTemp1
Procedure_Return
End
Get Create (RefClass(cComChilkatMailMan)) To hoMailman
If (Not(IsComObjectCreated(hoMailman))) Begin
Send CreateComObject of hoMailman
End
// Configure the SMTP server connection. These connections will travel through the tunnel.
Set ComSmtpHost Of hoMailman To "smtp.example.com"
Set ComSmtpPort Of hoMailman To 465
Set ComSmtpSsl Of hoMailman To True
Set ComSmtpUsername Of hoMailman To "user@example.com"
Set ComSmtpPassword Of hoMailman To "myPassword"
// Tell MailMan to route its connections through the existing tunnel.
Get pvComObject of hoSshTunnel to vSshTunnel
Get ComUseSshTunnel Of hoMailman vSshTunnel To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoMailman To sTemp1
Showln sTemp1
Procedure_Return
End
// SMTP operations now travel through the shared SSH tunnel.
Get ComVerifySmtpLogin Of hoMailman To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoMailman To sTemp1
Showln sTemp1
Procedure_Return
End
Showln "Authenticated with the SMTP server through the SSH tunnel."
End_Procedure