Sample code for 30+ languages & platforms
AutoIt

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 AutoIt Downloads

AutoIt
Local $bSuccess = False

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

$oMailman = ObjCreate("Chilkat.MailMan")

;  Configure the POP3 server connection.
$oMailman.MailHost = "pop.example.com"
$oMailman.MailPort = 995
$oMailman.PopSsl = True
$oMailman.PopUsername = "user@example.com"
$oMailman.PopPassword = "myPassword"

;  Open and authenticate the SSH tunnel.
$bSuccess = $oMailman.SshOpenTunnel("ssh.example.com",22)
If ($bSuccess = False) Then
    ConsoleWrite($oMailman.LastErrorText & @CRLF)
    Exit
EndIf

$bSuccess = $oMailman.SshAuthenticatePw("sshUser","sshPassword")
If ($bSuccess = False) Then
    ConsoleWrite($oMailman.LastErrorText & @CRLF)
    Exit
EndIf

;  ... perform mail operations through the tunnel ...
Local $iCount = $oMailman.GetMailboxCount()
If ($iCount < 0) Then
    ConsoleWrite("Failed to get the mailbox count." & @CRLF)
Else
    ConsoleWrite("Mailbox count: " & $iCount & @CRLF)
EndIf

;  Close the SSH tunnel when finished with it.
$bSuccess = $oMailman.SshCloseTunnel()
If ($bSuccess = False) Then
    ConsoleWrite($oMailman.LastErrorText & @CRLF)
    Exit
EndIf

ConsoleWrite("SSH tunnel closed." & @CRLF)