Java Requires Chilkat v11.0.0+
Chilkat2 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.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Email;
public class ChilkatExample {
public static void main(String[] args) {
boolean success = false;
Email email = new Email();
// Load an email from a .eml
try {
email.loadEml("embeddedEmail.eml");
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
// Display how many attached emails are embedded within
// this one:
int numAttached = email.getNumAttachedMessages();
System.out.println("numAttached = " + numAttached);
// Get the 1st attached message.
Email email2 = new Email();
try {
email.getAttachedEmail(0, email2);
success = true;
} catch (ChilkatException e) {
success = false;
}
if (success) {
// Display the subject, From, and a header field...
System.out.println(email2.getSubject());
System.out.println(email2.getFrom());
System.out.println(email2.getHeaderField("X-SOMETHING"));
}
}
}