Android™
Android™
Explicitly Begin a POP3 Session
See more POP3 Examples
Demonstrates the Chilkat MailMan.Pop3BeginSession method, which explicitly begins a POP3 session by connecting to the POP3 server and authenticating using the current POP3 property settings. Calling it is optional. This example begins a session, performs a mailbox operation, and ends the session.
Background:
Pop3BeginSession combines connecting and authenticating into one call. Chilkat does this automatically when a mailbox operation needs it, so the value of calling it explicitly is control: you open one session, perform several operations against it, and close it with Pop3EndSession — avoiding repeated connect/authenticate round trips and keeping deletion marks within a single, well-defined session.Chilkat Android™ Downloads
// 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.Pop3BeginSession method, which explicitly begins a POP3 session
// by connecting to the POP3 server and authenticating using the current POP3 property
// settings.
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");
// Explicitly begin the POP3 session (connect + authenticate).
success = mailman.Pop3BeginSession();
if (success == false) {
Log.i(TAG, mailman.lastErrorText());
return;
}
// Perform one or more mailbox operations within this single session.
Log.i(TAG, "Mailbox count: " + String.valueOf(mailman.GetMailboxCount()));
// End the session when finished.
success = mailman.Pop3EndSession();
if (success == false) {
Log.i(TAG, mailman.lastErrorText());
return;
}
Log.i(TAG, "POP3 session completed.");
}
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."
}
}