Sample code for 30+ languages & platforms
Android™

Delete a Bundle of POP3 Messages

See more POP3 Examples

Demonstrates the Chilkat MailMan.DeleteBundle method, which deletes POP3 messages using the UIDLs stored in the X-UIDL headers of the Email objects in an EmailBundle. An email without an X-UIDL header is skipped. This example fetches all messages and deletes them.

Background: DeleteBundle is the batch version of DeleteEmail: it marks every message in a downloaded bundle for deletion in one call. A typical "download and clear the mailbox" workflow is to fetch all messages, process them, then delete the whole bundle. Because a bundle can be filtered or built selectively, you can also delete just the subset you no longer need. The deletions commit when the POP3 session ends.

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.DeleteBundle method, which deletes POP3 messages using the UIDLs
    //  stored in the X-UIDL headers of the Email objects in an EmailBundle.  An email without an
    //  X-UIDL header is skipped.

    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");

    //  Fetch all messages (headers are enough; each carries an X-UIDL header).
    CkEmailBundle bundle = new CkEmailBundle();

    success = mailman.FetchAll(true,true,0,bundle);
    if (success == false) {
        Log.i(TAG, mailman.lastErrorText());
        return;
        }

    //  Delete every message in the bundle.
    success = mailman.DeleteBundle(bundle);
    if (success == false) {
        Log.i(TAG, mailman.lastErrorText());
        return;
        }

    //  Unless the ImmediateDelete property is set to true, the messages are only marked for
    //  deletion.  End the POP3 session (which sends the QUIT command) to commit the deletions.
    success = mailman.Pop3EndSession();
    if (success == false) {
        Log.i(TAG, mailman.lastErrorText());
        return;
        }

    Log.i(TAG, "Deleted " + String.valueOf(bundle.get_MessageCount()) + " messages from the POP3 server.");

    //  Note: Explicitly connecting/authenticating is optional.  Chilkat MailMan automatically
    //  connects and authenticates -- using the property settings above -- whenever a server
    //  operation requires it.  Calling the explicit connect/authenticate methods can still be
    //  helpful to determine whether a failure occurs while connecting or while authenticating.

  }

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