Sample code for 30+ languages & platforms
Android™

Embed a Message as message/rfc822

See more MIME Examples

Demonstrates the Chilkat Mime.NewMessageRfc822 method, which clears the object and initializes it as a message/rfc822 entity whose body is a serialized copy of another Mime. The only argument is the message to embed.

Background: message/rfc822 wraps a whole email as the body of another — the mechanism behind forwarding a message "as attachment" or bundling one message inside another. The inner message is copied at the time of the call, so later edits to the source do not change the embedded copy. The result is a self-contained part a mail client will present as a nested message.

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 Mime.NewMessageRfc822 method, which clears the current object and initializes
    //  it as a message/rfc822 entity whose body is a serialized copy of another Mime.  The only
    //  argument is the Mime to embed.

    //  Build the inner message to embed.
    CkMime innerMsg = new CkMime();
    success = innerMsg.SetHeaderField("Subject","Forwarded message");
    if (success == false) {
        Log.i(TAG, innerMsg.lastErrorText());
        return;
        }

    success = innerMsg.SetBodyFromPlainText("This is the original message being forwarded.");
    if (success == false) {
        Log.i(TAG, innerMsg.lastErrorText());
        return;
        }

    //  Wrap it as message/rfc822 (an embedded/forwarded email).
    CkMime mime = new CkMime();
    success = mime.NewMessageRfc822(innerMsg);
    if (success == false) {
        Log.i(TAG, mime.lastErrorText());
        return;
        }

    Log.i(TAG, "Content-Type: " + mime.contentType());

  }

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