Android™
Android™
Get an Email's MIME into a StringBuilder
See more Email Object Examples
Demonstrates the Chilkat Email.GetMimeSb method, which returns the email as MIME text (header, body or bodies, related items, and all attachments) by appending it to a StringBuilder object. This example builds a message and appends its MIME to a StringBuilder.
Background: This is a
StringBuilder-based alternative to GetMime, which returns a plain string. Writing into a StringBuilder is more efficient when the MIME is large or when you intend to further manipulate it — searching, replacing, or accumulating additional text — without creating many intermediate string copies.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 GetMimeSb method, which returns the email as MIME text (headers, bodies,
// related items, and attachments), appending it to a StringBuilder object.
CkEmail email = new CkEmail();
email.put_Subject("GetMimeSb example");
email.put_From("alice@example.com");
email.AddTo("Bob","bob@example.com");
email.put_Body("Hello!");
// Append the complete MIME to a StringBuilder.
CkStringBuilder sbMime = new CkStringBuilder();
success = email.GetMimeSb(sbMime);
if (success == false) {
Log.i(TAG, email.lastErrorText());
return true;
}
Log.i(TAG, sbMime.getAsString());
}
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."
}
}