Sample code for 30+ languages & platforms
Android™

Get the Full MIME of an Email

See more Email Object Examples

Demonstrates the Chilkat Email.GetMime method, which returns the email as RFC822/MIME text containing the headers, body representations, related items, and attachments. The result is suitable for saving as a .eml file. This example builds a message and prints its MIME.

Background: MIME is the on-the-wire text format of an email — the exact bytes a mail server sends and receives. GetMime serializes the in-memory Email object into that format, assembling headers, encoding attachments as Base64, and adding the multipart boundaries that separate the parts. It is the natural way to persist a message (as .eml), inspect exactly what will be transmitted, or hand the message to another system.

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

    //  Demonstrates the GetMime method, which returns the email as RFC822/MIME text containing
    //  the headers, body representations, related items, and attachments.

    CkEmail email = new CkEmail();
    email.put_Subject("GetMime example");
    email.put_From("alice@example.com");
    email.AddTo("Bob","bob@example.com");
    email.put_Body("Hello, this is the message body.");

    //  Get the complete RFC822/MIME text (suitable for saving as a .eml file).
    Log.i(TAG, email.getMime());

  }

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