Android™
Android™
Delete a POP3 Message via an Email Object
See more POP3 Examples
Demonstrates the Chilkat MailMan.DeleteEmail method, which deletes a POP3 message using the UIDL stored in the X-UIDL header of an Email object. The email must contain an X-UIDL header, which it does after being fetched from the server. This example fetches a message and then deletes it.
Background: When Chilkat downloads a POP3 message it records the server UIDL in an
X-UIDL header on the Email object. DeleteEmail uses that header to tell the server which message to remove — a natural "process then delete" flow: fetch a message, act on it, then delete it. As always in POP3, the deletion is only committed when the session ends (unless ImmediateDelete is set).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.DeleteEmail method, which deletes a POP3 message using the UIDL
// stored in the X-UIDL header of an Email object. The email must contain an X-UIDL header
// (as it does after being fetched from the server).
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 a message (headers are enough; the X-UIDL header identifies it on the server).
CkEmail email = new CkEmail();
success = mailman.FetchOne(true,0,1,email);
if (success == false) {
Log.i(TAG, mailman.lastErrorText());
return;
}
// Delete that message using its X-UIDL header.
success = mailman.DeleteEmail(email);
if (success == false) {
Log.i(TAG, mailman.lastErrorText());
return;
}
// Unless the ImmediateDelete property is set to true, the message is only marked for
// deletion. End the POP3 session (which sends the QUIT command) to commit the deletion.
success = mailman.Pop3EndSession();
if (success == false) {
Log.i(TAG, mailman.lastErrorText());
return;
}
Log.i(TAG, "Deleted the email 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."
}
}