Chilkat
HOME
Android™
ASP
Visual Basic
VB.NET
C#
iOS (IPhone)
Objective-C
C++
C
MFC
Delphi
FoxPro
Java
Perl
PHP Extension
PHP ActiveX
Python
PowerShell
Ruby
SQL Server
VBScript
IMAP SSH Tunneling (Port Forwarding)Demonstrates how to setup an SSH tunnel for IMAP. Downloads: MS Windows Visual C/C++ Libraries Linux/CentOS C/C++ Libraries MAC OS X C/C++ Libraries Solaris C/C++ Libraries C++ Builder Libraries #include <C_CkImap.h> #include <C_CkMessageSet.h> #include <C_CkEmailBundle.h> #include <C_CkEmail.h> void ChilkatSample(void) { HCkImap imap; BOOL success; const char * sshHostname; long sshPort; HCkMessageSet messageSet; BOOL fetchUids; HCkEmailBundle bundle; long i; HCkEmail email; imap = CkImap_Create(); // Anything unlocks the component and begins a fully-functional 30-day trial. success = CkImap_UnlockComponent(imap,"Anything for 30-day trial"); if (success != TRUE) { printf("%s\n",CkImap_lastErrorText(imap)); return; } // Connect to an SSH server and establish the SSH tunnel: // The SSH hostname may be a hostname or an // IP address, such as "192.168.1.108". // The port is typically 22 (the standard port for SSH). sshHostname = "www.mysshserver.com"; sshPort = 22; success = CkImap_SshTunnel(imap,sshHostname,sshPort); if (success != TRUE) { printf("%s\n",CkImap_lastErrorText(imap)); return; } // Authenticate with the SSH server via a login/password // or with a public key. // This example demonstrates SSH password authentication. // Note: This is not authenticating with the IMAP server, it is // for authenticating with the SSH server, which is separate. success = CkImap_SshAuthenticatePw(imap,"mySshLogin","mySshPassword"); if (success != TRUE) { printf("%s\n",CkImap_lastErrorText(imap)); return; } // OK, the SSH tunnel is setup. The IMAP component may // be used exactly the same as usual, except all communications // are sent through the SSH tunnel. // Connect to an IMAP server via the SSH tunnel. // Because the SSH tunnel has been previously setup, // this does not establish a direct connection with the IMAP // server. It directs the SSH server to establish the connection. success = CkImap_Connect(imap,"mail.chilkatsoft.com"); if (success != TRUE) { printf("%s\n",CkImap_lastErrorText(imap)); return; } // Authenticate with the IMAP server via the SSH tunnel. success = CkImap_Login(imap,"myLogin","myPassword"); if (success != TRUE) { printf("%s\n",CkImap_lastErrorText(imap)); return; } // Select an IMAP mailbox success = CkImap_SelectMailbox(imap,"Inbox"); if (success != TRUE) { printf("%s\n",CkImap_lastErrorText(imap)); return; } // We can choose to fetch UIDs or sequence numbers. fetchUids = TRUE; // Get the message IDs of all the emails in the mailbox messageSet = CkImap_Search(imap,"ALL",fetchUids); if (messageSet == 0 ) { printf("%s\n",CkImap_lastErrorText(imap)); return; } // Fetch the emails into a bundle object: bundle = CkImap_FetchBundle(imap,messageSet); if (bundle == 0 ) { CkMessageSet_Dispose(messageSet); printf("%s\n",CkImap_lastErrorText(imap)); return; } // Loop over the bundle and display the FROM and SUBJECT of each. for (i = 0; i <= CkEmailBundle_getMessageCount(bundle) - 1; i++) { email = CkEmailBundle_GetEmail(bundle,i); printf("%s\n",CkEmail_ck_from(email)); printf("%s\n",CkEmail_subject(email)); printf("--\n"); CkEmail_Dispose(email); } // Disconnect from the IMAP server. CkImap_Disconnect(imap); CkMessageSet_Dispose(messageSet); CkEmailBundle_Dispose(bundle); CkImap_Dispose(imap); } |
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2010 Chilkat Software, Inc. All Rights Reserved.