Android™
Android™
Set an Email Body with a Content-Type
See more Email Object Examples
Demonstrates the Chilkat Email.SetTextBody method, which sets the body of the email and also sets the Content-Type header field to the value in the second argument (a textual MIME type such as text/plain or text/html). If the email is already multipart/alternative, an alternative with the given content type is added, or replaced if one already exists. This example sets a plain-text body.
Background:
SetTextBody is the general body-setter where you name the MIME type, making it flexible for building multipart/alternative messages one representation at a time. When your goal is specifically a plain-text/HTML pair, the dedicated methods — SetHtmlBody with AddPlainTextAlternativeBody, or AddHtmlAlternativeBody — express the intended alternative structure more clearly.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);
// Demonstrates the SetTextBody method, which sets the body of the email and also sets the
// Content-Type header field to the value in the second argument (a textual MIME type such
// as text/plain or text/html). If the email is already multipart/alternative, an
// alternative with the given Content-Type is added (or replaced if one already exists).
CkEmail email = new CkEmail();
email.put_Subject("SetTextBody example");
// Set a plain-text body with Content-Type text/plain.
email.SetTextBody("This is the plain-text body of the message.","text/plain");
Log.i(TAG, "HasPlainTextBody: " + String.valueOf(email.HasPlainTextBody()));
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."
}
}