Java
Java
Access Attached Message (Embedded Email)
How to access an email embedded within another email (i.e. an attached message).Chilkat Java Downloads
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;
CkEmail email = new CkEmail();
// Load an email from a .eml
success = email.LoadEml("embeddedEmail.eml");
if (success == false) {
System.out.println(email.lastErrorText());
return;
}
// Display how many attached emails are embedded within
// this one:
int numAttached = email.get_NumAttachedMessages();
System.out.println("numAttached = " + numAttached);
// Get the 1st attached message.
CkEmail email2 = new CkEmail();
success = email.GetAttachedEmail(0,email2);
if (success == true) {
// Display the subject, From, and a header field...
System.out.println(email2.subject());
System.out.println(email2.ck_from());
System.out.println(email2.getHeaderField("X-SOMETHING"));
}
}
}