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

POP3: Require an STLS Upgrade Before Authentication

Connect to a provider that supports POP STLS on port 110, require the TLS upgrade, then authenticate and obtain a message count. Set PopSsl=false, Pop3Stls=true, and enable certificate verification. Replace the generic host and credentials with settings issued by that provider. Use the provider's OAuth or app-password policy where applicable.

The former example was mislabeled: it connected to Gmail on port 995 using implicit TLS and never performed STLS. Gmail's documented POP configuration remains pop.gmail.com:995 with PopSsl=true; use Gmail POP OAuth2 for that connection.

The required STLS setting fails if the upgrade is unavailable. An opportunistic setting can leave a connection unencrypted and is not used here.

See the Gmail SMTP, IMAP, and POP3 guide for current authentication choices and Gmail-specific examples.

Reference documentation

Chilkat Android™ Downloads

Android™
// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;

import android.app.Activity;
import com.chilkatsoft.*;

import android.widget.TextView;
import android.os.Bundle;

public class SimpleActivity extends Activity {

  private static final String TAG = "Chilkat";

  // Called when the activity is first created.
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    boolean success = false;

    //  Assumes Chilkat is unlocked. See Global Unlock Sample.

    CkMailMan mailman = new CkMailMan();
    //  Use a provider that explicitly supports POP STLS on port 110.
    //  Gmail documents implicit TLS on pop.gmail.com:995 instead.
    mailman.put_MailHost("pop.example.com");
    mailman.put_MailPort(110);
    mailman.put_PopSsl(false);
    mailman.put_Pop3Stls(true);
    mailman.put_Pop3StlsIfPossible(false);
    mailman.put_RequireSslCertVerify(true);
    mailman.put_PopUsername("user@example.com");
    mailman.put_PopPassword("YOUR_PROVIDER_ISSUED_PASSWORD");
    success = mailman.Pop3BeginSession();
    if (success != true) {
        mailman.Pop3EndSessionNoQuit();
        Log.i(TAG, "POP connection or authentication failed. STLS must succeed before credentials are sent.");
        return;
        }

    int count = mailman.CheckMail();
    if (count < 0) {
        mailman.Pop3EndSessionNoQuit();
        Log.i(TAG, "Could not obtain the POP message count.");
        return;
        }

    Log.i(TAG, "Available POP messages: " + String.valueOf(count));
    success = mailman.Pop3EndSession();
    if (success != true) {
        Log.i(TAG, "The count was obtained, but closing the POP session failed.");
        }


  }

  static {
      System.loadLibrary("chilkat");

      // Note: If the incorrect library name is passed to System.loadLibrary,
      // then you will see the following error message at application startup:
      //"The application <your-application-name> has stopped unexpectedly. Please try again."
  }
}