Sample code for 30+ languages & platforms
Android™

Render an Email to MIME Bytes in a BinData

See more SMTP Examples

Demonstrates the Chilkat MailMan.RenderToMimeBd method, which renders an Email object as MIME bytes and appends the result to a BinData, without sending the email. This example renders a message into a BinData and prints the byte count.

Background: This is the binary version of RenderToMime. A BinData holds raw bytes, which is the right container when you want the rendered MIME as binary — to write it directly to a file or socket, hash it, or hand it to another API expecting a byte buffer — rather than as text.

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.RenderToMimeBd method, which renders an Email object as MIME
    //  bytes and appends the result to a BinData (without sending the email).

    CkMailMan mailman = new CkMailMan();

    //  Build the email to render.
    CkEmail email = new CkEmail();
    email.put_Subject("Rendered email");
    email.put_From("alice@example.com");
    email.AddTo("Bob","bob@example.com");
    email.put_Body("This message is rendered to MIME bytes in a BinData.");

    //  Render the MIME into a BinData.
    CkBinData bdMime = new CkBinData();

    success = mailman.RenderToMimeBd(email,bdMime);
    if (success == false) {
        Log.i(TAG, mailman.lastErrorText());
        return;
        }

    Log.i(TAG, "Rendered MIME size (bytes) = " + String.valueOf(bdMime.get_NumBytes()));

  }

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