Sample code for 30+ languages & platforms
CkJava Requires Chilkat v11.0.0+

List message headers in their original field order

See more Email Object Examples

Walk the top-level header fields by index. Read the name and value at the same index so repeated fields such as Received retain their separate values. Attachment headers belong to the attachment’s MIME part.

Chilkat CkJava Downloads

CkJava
import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {
    boolean success = false;

    //  Assumes Chilkat is unlocked. See Global Unlock Sample.

    CkEmail email = new CkEmail();
    success = email.LoadEml("message.eml");
    if (success != true) {
        System.out.println(email.lastErrorText());
        return;
        }

    int i = 0;
    while ((i < email.get_NumHeaderFields())) {
        //  Read the value by index because names can repeat.
        System.out.println(email.getHeaderFieldName(i) + ": " + email.getHeaderFieldValue(i));
        i = i+1;
        }
  }
}