Android™ Requires Chilkat v11.0.0+
Android™
Create, save, and reopen a plain-text email
See more Email Object Examples
Set the sender, recipient, subject, and plain-text body. Save the result as an EML file, then open it in a second Email object and read its contents.
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_From("Sam Lee <sam@example.com>");
success = email.AddTo("Alex Rivera","alex@example.net");
if (success != true) {
Log.i(TAG, email.lastErrorText());
return;
}
email.put_Subject("Hello");
email.put_Body("This is a plain-text message.");
success = email.SaveEml("message.eml");
if (success != true) {
Log.i(TAG, email.lastErrorText());
return;
}
CkEmail received = new CkEmail();
success = received.LoadEml("message.eml");
if (success != true) {
Log.i(TAG, received.lastErrorText());
return;
}
Log.i(TAG, received.ck_from());
Log.i(TAG, received.subject());
Log.i(TAG, received.getPlainTextBody());
}
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."
}
}