Android™ Requires Chilkat v11.0.0+
Android™
Create an email with plain-text and HTML bodies
See more Email Object Examples
Set the From and Reply-To addresses, add a recipient, and provide plain-text and HTML versions of the same body. Save the message as text-and-html.eml.
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;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
CkEmail email = new CkEmail();
email.put_FromName("Sam Lee");
email.put_FromAddress("sam@example.com");
email.put_ReplyTo("replies@example.com");
success = email.AddTo("Alex Rivera","alex@example.net");
if (success != true) {
Log.i(TAG, email.lastErrorText());
return;
}
email.put_Subject("Sample message");
email.put_Charset("utf-8");
// A custom header can carry a reference alongside the standard message fields.
email.AddHeaderField("X-Reference-ID","REF-42");
success = email.AddPlainTextAlternativeBody("Read more at https://example.com/details.");
if (success != true) {
Log.i(TAG, email.lastErrorText());
return;
}
success = email.AddHtmlAlternativeBody("<p><a href='https://example.com/details'>Read more</a></p>");
if (success != true) {
Log.i(TAG, email.lastErrorText());
return;
}
success = email.SaveEml("text-and-html.eml");
if (success != true) {
Log.i(TAG, email.lastErrorText());
return;
}
Log.i(TAG, "Saved text-and-html.eml.");
}
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."
}
}