Android™ Requires Chilkat v11.0.0+
Android™
Preserve the original email and save a modified copy
See more Email Object Examples
Use with-attachments.eml as a stand-in for bytes from an IMAP fetch or a message queue. Preserve those bytes first. Parse them into an Email object, add a local processing header, and serialize the result into a separate buffer. The archived input remains suitable for later byte-level inspection.
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.
CkBinData mimeBytes = new CkBinData();
success = mimeBytes.LoadFile("with-attachments.eml");
if (success != true) {
Log.i(TAG, "Failed: mimeBytes.LoadFile.");
return;
}
success = mimeBytes.WriteFile("received-original.eml");
if (success != true) {
Log.i(TAG, "Failed: mimeBytes.WriteFile.");
return;
}
CkEmail email = new CkEmail();
success = email.SetFromMimeBd(mimeBytes);
if (success != true) {
Log.i(TAG, email.lastErrorText());
return;
}
email.AddHeaderField("X-Workflow-State","reviewed");
// GetMimeBd appends to its destination. Use a fresh buffer for this message.
CkBinData rendered = new CkBinData();
success = email.GetMimeBd(rendered);
if (success != true) {
Log.i(TAG, email.lastErrorText());
return;
}
success = rendered.WriteFile("reviewed.eml");
if (success != true) {
Log.i(TAG, "Failed: rendered.WriteFile.");
return;
}
Log.i(TAG, "Archived received-original.eml and saved reviewed.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."
}
}