Sample code for 30+ languages & platforms
Android™

Send a Raw POP3 Command

See more POP3 Examples

Demonstrates the Chilkat MailMan.Pop3SendRawCommand method, which sends a raw command to the POP3 server and returns the server's response. The second argument specifies the charset to use if the command contains non-US-ASCII characters. This example sends the POP3 STAT command within an open session.

Background: POP3 is a simple line-based text protocol — the client sends short commands like STAT, LIST, UIDL, or RETR and the server replies with +OK or -ERR. This method is an escape hatch for issuing a command Chilkat doesn't wrap directly, or a server-specific extension. Note that the session must already be open, since a raw command assumes an authenticated connection.

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;

    //  Demonstrates the MailMan.Pop3SendRawCommand method, which sends a raw command to the POP3
    //  server and returns the server's response.  The second argument is the charset used if the
    //  command contains non-US-ASCII characters.

    CkMailMan mailman = new CkMailMan();

    //  Configure the POP3 server connection.
    mailman.put_MailHost("pop.example.com");
    mailman.put_MailPort(995);
    mailman.put_PopSsl(true);
    mailman.put_PopUsername("user@example.com");
    mailman.put_PopPassword("myPassword");

    success = mailman.Pop3BeginSession();
    if (success == false) {
        Log.i(TAG, mailman.lastErrorText());
        return;
        }

    //  Send the raw POP3 STAT command, which returns the message count and maildrop size.
    String response = mailman.pop3SendRawCommand("STAT","us-ascii");
    if (mailman.get_LastMethodSuccess() == false) {
        Log.i(TAG, mailman.lastErrorText());
        return;
        }

    Log.i(TAG, "STAT response: " + response);

    success = mailman.Pop3EndSession();
    if (success == false) {
        Log.i(TAG, mailman.lastErrorText());
        return;
        }


  }

  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."
  }
}