Sample code for 30+ languages & platforms
VBScript

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

VBScript
Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
'Create a Unicode (utf-16) output text file.
Set outFile = fso.CreateTextFile("output.txt", True, True)

success = 0

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

set mailman = CreateObject("Chilkat.MailMan")

'  Configure the POP3 server connection.
mailman.MailHost = "pop.example.com"
mailman.MailPort = 995
mailman.PopSsl = 1
mailman.PopUsername = "user@example.com"
mailman.PopPassword = "myPassword"

'  Open and authenticate the SSH tunnel.
success = mailman.SshOpenTunnel("ssh.example.com",22)
If (success = 0) Then
    outFile.WriteLine(mailman.LastErrorText)
    WScript.Quit
End If

success = mailman.SshAuthenticatePw("sshUser","sshPassword")
If (success = 0) Then
    outFile.WriteLine(mailman.LastErrorText)
    WScript.Quit
End If

'  ... perform mail operations through the tunnel ...
count = mailman.GetMailboxCount()
If (count < 0) Then
    outFile.WriteLine("Failed to get the mailbox count.")
Else
    outFile.WriteLine("Mailbox count: " & count)
End If

'  Close the SSH tunnel when finished with it.
success = mailman.SshCloseTunnel()
If (success = 0) Then
    outFile.WriteLine(mailman.LastErrorText)
    WScript.Quit
End If

outFile.WriteLine("SSH tunnel closed.")

outFile.Close