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

Read an attached email

See more Email Object Examples

Open forward-as-attachment.eml from the forwarding example. Read the cover note’s subject, then open each attached message and inspect its own headers and attachment count. This works even when the outer message has no ordinary files.

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 wrapper = new CkEmail();
    success = wrapper.LoadEml("forward-as-attachment.eml");
    if (success != true) {
        System.out.println(wrapper.lastErrorText());
        return;
        }

    System.out.println("Cover note: " + wrapper.subject());
    if (wrapper.get_NumAttachedMessages() == 0) {
        System.out.println("No attached messages.");
        return;
        }

    CkEmail nested = new CkEmail();
    int i = 0;
    while ((i < wrapper.get_NumAttachedMessages())) {
        success = wrapper.GetAttachedEmail(i,nested);
        if (success != true) {
            System.out.println(wrapper.lastErrorText());
            return;
            }

        System.out.println("Original author: " + nested.ck_from());
        System.out.println("Original subject: " + nested.subject());
        System.out.println("Files on the original: " + nested.get_NumAttachments());
        i = i+1;
        }
  }
}