Android™
Android™
Prepend Added Header Fields to the Top
See more Email Object Examples
Demonstrates the Chilkat Email.PrependHeaders property. When true, header fields added through AddHeaderField or AddHeaderField2 are placed at the top of the header rather than appended at the bottom (the default is false). This affects only fields added after the property is set — it does not reorder fields that are already present. This example enables prepending and adds two custom header fields.
Background: In a MIME message the order of header fields is mostly cosmetic, but there are cases where "top vs bottom" matters — for instance, trace headers like
Received are conventionally added to the top so the most recent hop appears first, and some pipelines expect certain fields early in the header block. PrependHeaders gives you control over placement when you add your own custom fields.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 Email.PrependHeaders property. When true, header fields added via
// AddHeaderField (or AddHeaderField2) are prepended to the top of the header instead of
// appended to the bottom. The default is false.
CkEmail email = new CkEmail();
email.put_Subject("Prepend headers demo");
email.put_From("mary@example.com");
// Cause subsequently-added header fields to go to the top of the header.
email.put_PrependHeaders(true);
email.AddHeaderField("X-Custom-One","first value");
email.AddHeaderField("X-Custom-Two","second value");
Log.i(TAG, email.header());
}
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."
}
}