Programming Examples

ChilkatHOMEAndroid™ASPVisual BasicVB.NETC#iOS (IPhone)Objective-CC++CMFCDelphiFoxProJavaPerl
PHP ExtensionPHP ActiveXPythonPowerShellRubySQL ServerVBScript

C Examples

Bounced Mail
Bz2
Certificates/Keys
Charset
CSV
DKIM / DomainKey
Diffie-Hellman
DSA
Email Object
Encryption
FileAccess
FTP
HTML Conversion
HTTP
IMAP
MHT / HTML Email
MIME
NTLM
POP3
RSA
SMTP
Socket
Spider
SSH Key
SSH
SSH Tunnel
SFTP
Tar
Upload
XML
Zip
Amazon S3

 

 

 

 

 

 

 

 

SSL POP3 with Certificates

Demonstrates how to use a client-side certificate with an SSL connection to a POP3 server. Also demonstrates how to get the POP3 server's SSL certificate.

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_CkMailMan.h>
#include <C_CkCert.h>

void ChilkatSample(void)
    {
    HCkMailMan mailman;
    BOOL success;
    HCkCert clientCert;
    HCkCert serverCert;

    //  The mailman object is used for receiving (POP3)
    //  and sending (SMTP) email.
    mailman = CkMailMan_Create();

    //  Any string argument automatically begins the 30-day trial.

    success = CkMailMan_UnlockComponent(mailman,"30-day trial");
    if (success != TRUE) {
        printf("Component unlock failed\n");
        return;
    }

    //  Set the GMail account POP3 properties.
    CkMailMan_putMailHost(mailman,"pop.gmail.com");
    CkMailMan_putPopUsername(mailman,"myLogin");
    CkMailMan_putPopPassword(mailman,"****");
    CkMailMan_putPopSsl(mailman,TRUE);
    CkMailMan_putMailPort(mailman,995);

    //  Use our certificate, which is already installed
    //  in our current-user certificate store on the computer.
    clientCert = CkCert_Create();
    success = CkCert_LoadByCommonName(clientCert,"Chilkat Software, Inc.");
    if (success != TRUE) {
        printf("%s\n",CkCert_lastErrorText(clientCert));
        return;
    }

    //  Note: The GMail POP3 server does not require that you
    //  have a client cert.  This example only demonstrates
    //  how you may use a client certificate.  Typically,
    //  higher-security systems may require a client-side SSL cert.
    CkMailMan_SetSslClientCert(mailman,clientCert);

    //  Establish a POP3 connection:
    success = CkMailMan_Pop3BeginSession(mailman);
    if (success != TRUE) {
        printf("%s\n",CkMailMan_lastErrorText(mailman));
        return;
    }

    //  Let's look at the LastErrorText to see the details
    //  of the successful connection.  We should see our cert:
    printf("%s\n",CkMailMan_lastErrorText(mailman));

    //  OK, now examine the server's cert:

    serverCert = CkMailMan_GetPop3SslServerCert(mailman);
    if (serverCert == 0 ) {
        printf("No server cert available.\n");
    }
    else {
        printf("Server SSL certificate:\n");
        printf("%s\n",CkCert_subjectDN(serverCert));

        //  Was the server certificate verified?
        //  It's not necessarily an error if the SSL Server cert is not verified.
        if (CkMailMan_getPop3SslServerCertVerified(mailman) == TRUE) {
            printf("Server SSL certificate was verified.\n");
        }
        else {
            printf("Server SSL certificate was NOT verified!\n");
        }

    }


    CkMailMan_Dispose(mailman);
    CkCert_Dispose(clientCert);

    }

Need a specific example? Send a request to support@chilkatsoft.com

© 2000-2010 Chilkat Software, Inc. All Rights Reserved.