Tcl
Tcl
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 Tcl Downloads
load ./chilkat.dll
set 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.
set sshTunnel [new_CkSocket]
set success [CkSocket_SshOpenTunnel $sshTunnel "ssh.example.com" 22]
if {$success == 0} then {
puts [CkSocket_lastErrorText $sshTunnel]
delete_CkSocket $sshTunnel
exit
}
set success [CkSocket_SshAuthenticatePw $sshTunnel "sshUser" "sshPassword"]
if {$success == 0} then {
puts [CkSocket_lastErrorText $sshTunnel]
delete_CkSocket $sshTunnel
exit
}
set mailman [new_CkMailMan]
# Configure the SMTP server connection. These connections will travel through the tunnel.
CkMailMan_put_SmtpHost $mailman "smtp.example.com"
CkMailMan_put_SmtpPort $mailman 465
CkMailMan_put_SmtpSsl $mailman 1
CkMailMan_put_SmtpUsername $mailman "user@example.com"
CkMailMan_put_SmtpPassword $mailman "myPassword"
# Tell MailMan to route its connections through the existing tunnel.
set success [CkMailMan_UseSshTunnel $mailman $sshTunnel]
if {$success == 0} then {
puts [CkMailMan_lastErrorText $mailman]
delete_CkSocket $sshTunnel
delete_CkMailMan $mailman
exit
}
# SMTP operations now travel through the shared SSH tunnel.
set success [CkMailMan_VerifySmtpLogin $mailman]
if {$success == 0} then {
puts [CkMailMan_lastErrorText $mailman]
delete_CkSocket $sshTunnel
delete_CkMailMan $mailman
exit
}
puts "Authenticated with the SMTP server through the SSH tunnel."
delete_CkSocket $sshTunnel
delete_CkMailMan $mailman