Sample code for 30+ languages & platforms
Android™

Load Emails from a .mbx Mailbox File

See more POP3 Examples

Demonstrates the Chilkat MailMan.LoadMbxFile method, which loads emails from a .mbx mailbox file and stores them in an EmailBundle. If a filter has been configured, only the matching emails are returned. This example loads a local mailbox file and iterates the resulting bundle.

Background: An .mbx file is a single-file mailbox format that stores many messages concatenated together — historically produced by Outlook Express and similar clients. LoadMbxFile parses that archive into individual Email objects, which is useful for importing, migrating, or analyzing old mail without any server connection. No POP3 or SMTP session is involved — this reads purely from disk.

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.LoadMbxFile method, which loads emails from a .mbx mailbox file
    //  and stores them in an EmailBundle.  If a filter has been configured, only the matching
    //  emails are returned.

    CkMailMan mailman = new CkMailMan();

    //  Load emails from a local .mbx mailbox file (no server connection is made).
    CkEmailBundle bundle = new CkEmailBundle();

    success = mailman.LoadMbxFile("qa_data/mbx/inbox.mbx",bundle);
    if (success == false) {
        Log.i(TAG, mailman.lastErrorText());
        return;
        }

    int n = bundle.get_MessageCount();
    Log.i(TAG, "Loaded " + String.valueOf(n) + " emails from the .mbx file.");

    CkEmail email = new CkEmail();
    int i;
    for (i = 0; i <= n - 1; i++) {
        success = bundle.EmailAt(i,email);
        Log.i(TAG, email.subject());
        }

    //  Note: The path "qa_data/mbx/inbox.mbx" is a relative local filesystem path,
    //  relative to the current working directory of the running application.

  }

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