Sample code for 30+ languages & platforms
Visual FoxPro

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 Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loMailman
LOCAL lnCount

lnSuccess = 0

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

loMailman = CreateObject('Chilkat.MailMan')

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

*  Open and authenticate the SSH tunnel.
lnSuccess = loMailman.SshOpenTunnel("ssh.example.com",22)
IF (lnSuccess = 0) THEN
    ? loMailman.LastErrorText
    RELEASE loMailman
    CANCEL
ENDIF

lnSuccess = loMailman.SshAuthenticatePw("sshUser","sshPassword")
IF (lnSuccess = 0) THEN
    ? loMailman.LastErrorText
    RELEASE loMailman
    CANCEL
ENDIF

*  ... perform mail operations through the tunnel ...
lnCount = loMailman.GetMailboxCount()
IF (lnCount < 0) THEN
    ? "Failed to get the mailbox count."
ELSE
    ? "Mailbox count: " + STR(lnCount)
ENDIF

*  Close the SSH tunnel when finished with it.
lnSuccess = loMailman.SshCloseTunnel()
IF (lnSuccess = 0) THEN
    ? loMailman.LastErrorText
    RELEASE loMailman
    CANCEL
ENDIF

? "SSH tunnel closed."

RELEASE loMailman