Sample code for 30+ languages & platforms
Java Requires Chilkat v11.0.0+

POP3 SSL - Read POP3 Email over TLS/SSL on Port 995

Demonstrates how to connect via TLS/SSL to a POP3 server and read email. This assumes that the POP3 server supports SSL.

Chilkat Java Downloads

Chilkat2 Java
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Email;
import com.chilkatsoft.chilkat2.EmailBundle;
import com.chilkatsoft.chilkat2.MailMan;

public class ChilkatExample {

    public static void main(String[] args) {
        // This example requires the Chilkat API to have been previously unlocked.
        // See Global Unlock Sample for sample code.

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

        // Set the POP3 server's hostname
        mailman.setMailHost("pop.gmail.com");

        // Set the POP3 login/password.
        mailman.setPopUsername("****@gmail.com");
        mailman.setPopPassword("****");

        // Indicate that we want TLS/SSL.  Also, set the port to 995:
        mailman.setMailPort(995);
        mailman.setPopSsl(true);

        EmailBundle bundle = new EmailBundle();
        boolean keepOnServer = true;
        boolean headersOnly = false;
        // Irrelevent because we are NOT downloading headers-only
        int numBodyLines = 0;
        try {
            mailman.fetchAll(keepOnServer, headersOnly, numBodyLines, bundle);
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        Email email = new Email();
        int i = 0;
        while (i < bundle.getMessageCount()) {
            bundle.emailAt(i, email);

            // Display the From email address and the subject.
            System.out.println("From: " + email.getFrom());
            System.out.println("Subject: " + email.getSubject());
            i = i + 1;
        }
    }
}