Java Examples

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

Java Examples

Quick Start
Unicode
Bz2
Certificates
CSV
Email
Encryption
FTP
HTML Conversion
HTTP
IMAP
MHT
MIME
POP3
RSA
S/MIME
SFTP
Signatures
SMTP
Socket / SSL
Spider
SSH
SSH Key
SSH Tunnel
Tar
Upload
XML
XMP
Zip

More Examples...
Amazon S3
Email Object
DKIM / DomainKey
NTLM
FileAccess
RSS
Atom
String
Byte Array
Self-Extractor
Service
PPMD
Deflate
DH Key Exchange
DSA
Bzip2
LZW

 

 

 

 

 

 

 

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.

 Chilkat Java Library Downloads for Windows, Linux, and MAC OS X

import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {
    //  The mailman object is used for receiving (POP3)
    //  and sending (SMTP) email.
    CkMailMan mailman = new CkMailMan();

    //  Any string argument automatically begins the 30-day trial.
    boolean success;
    success = mailman.UnlockComponent("30-day trial");
    if (success != true) {
        System.out.println("Component unlock failed");
        return;
    }

    //  Set the GMail account POP3 properties.
    mailman.put_MailHost("pop.gmail.com");
    mailman.put_PopUsername("chilkat.support");
    mailman.put_PopPassword("****");
    mailman.put_PopSsl(true);
    mailman.put_MailPort(995);

    //  Use our certificate, which is already installed
    //  in our current-user certificate store on the computer.
    CkCert clientCert = new CkCert();
    success = clientCert.LoadByCommonName("Chilkat Software, Inc.");
    if (success != true) {
        System.out.println(clientCert.lastErrorText());
        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.
    mailman.SetSslClientCert(clientCert);

    //  Establish a POP3 connection:
    success = mailman.Pop3BeginSession();
    if (success != true) {
        System.out.println(mailman.lastErrorText());
        return;
    }

    //  Let's look at the LastErrorText to see the details
    //  of the successful connection.  We should see our cert:
    System.out.println(mailman.lastErrorText());

    //  OK, now examine the server's cert:
    CkCert serverCert;
    serverCert = mailman.GetPop3SslServerCert();
    if (serverCert == null ) {
        System.out.println("No server cert available.");
    }
    else {
        System.out.println("Server SSL certificate:");
        System.out.println(serverCert.subjectDN());

        //  Was the server certificate verified?
        //  It's not necessarily an error if the SSL Server cert is not verified.
        if (mailman.get_Pop3SslServerCertVerified() == true) {
            System.out.println("Server SSL certificate was verified.");
        }
        else {
            System.out.println("Server SSL certificate was NOT verified!");
        }

    }


  }
}

 

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