Android™
Android™
Set the HTML Body of an Email
See more Email Object Examples
Demonstrates the Chilkat Email.SetHtmlBody method, which creates or replaces the text/html body of an email. It does not automatically create a plain-text alternative. This example sets an HTML body and confirms its presence.
Background:
SetHtmlBody gives you explicit control over the HTML representation, unlike the general Body property which guesses the body type from the content. For a well-formed message you would typically also add a plain-text alternative (with AddPlainTextAlternativeBody) so text-only clients, accessibility tools, and spam filters have a fallback to read.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 SetHtmlBody method, which creates or replaces the text/html body of an
// email. It does not automatically create a plain-text alternative.
CkEmail email = new CkEmail();
email.put_Subject("Set HTML body");
// Set the HTML body.
email.SetHtmlBody("<html><body><h1>Welcome</h1><p>This is an HTML email.</p></body></html>");
Log.i(TAG, "HasHtmlBody: " + String.valueOf(email.HasHtmlBody()));
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."
}
}