Sample code for 30+ languages & platforms
Android™

Delete a Set of POP3 Messages by UIDL

See more POP3 Examples

Demonstrates the Chilkat MailMan.DeleteUidlSet method, which marks the POP3 messages whose UIDLs are listed in a StringTable for deletion. Chilkat processes the UIDL set and sends a DELE command for each located message. This example deletes two messages by UIDL.

Background: When you already know exactly which messages to remove — by their stable UIDLs — DeleteUidlSet deletes them all in one call without first downloading them. It is the efficient counterpart to fetching-then-deleting: for example, after processing messages elsewhere, hand back just their UIDLs to clear them. The deletions are committed when the POP3 session ends (unless ImmediateDelete is set).

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.DeleteUidlSet method, which marks the POP3 messages whose UIDLs
    //  are listed in a StringTable for deletion.  Chilkat sends DELE for each located message.

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

    //  Build the set of UIDLs to delete.
    CkStringTable uidls = new CkStringTable();
    uidls.Append("0000000123abcdef");
    uidls.Append("0000000124abcdef");

    //  Mark the messages for deletion.

    success = mailman.DeleteUidlSet(uidls);
    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 the UIDL set 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."
  }
}