Android™
Android™
Make a Copy of an Email
See more Email Object Examples
Demonstrates the Chilkat Email.MakeCopy method, which copies the entire state of this email into another Email object — message content, recipients, headers, body representations, attachments, and related items. This example copies an email and reads a couple of fields from the copy.
Background: A deep copy gives you an independent duplicate: changes to one object do not affect the other. This is handy for template-and-tweak workflows — build a base message once, copy it per recipient, then vary only the recipient or a few fields — without risk of one send's edits bleeding into the next.
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 MakeCopy method, which copies the entire state of this email into
// another Email object -- message content, recipients, headers, bodies, attachments, and
// related items.
CkEmail email = new CkEmail();
email.put_Subject("Original");
email.put_From("alice@example.com");
email.AddTo("Bob","bob@example.com");
email.put_Body("Original body.");
// Copy the entire email into a new Email object.
CkEmail copy = new CkEmail();
success = email.MakeCopy(copy);
if (success == false) {
Log.i(TAG, email.lastErrorText());
return true;
}
Log.i(TAG, "Copy subject: " + copy.subject());
Log.i(TAG, "Copy NumTo: " + String.valueOf(copy.get_NumTo()));
}
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."
}
}