Java Requires Chilkat v11.0.0+
Java
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 Java Downloads
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Email;
public class ChilkatExample {
public static void main(String[] args) {
// Assumes Chilkat is unlocked. See Global Unlock Sample.
Email wrapper = new Email();
try {
wrapper.loadEml("forward-as-attachment.eml");
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
System.out.println("Cover note: " + wrapper.getSubject());
if (wrapper.getNumAttachedMessages() == 0) {
System.out.println("No attached messages.");
return;
}
Email nested = new Email();
int i = 0;
while (i < wrapper.getNumAttachedMessages()) {
try {
wrapper.getAttachedEmail(i, nested);
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
System.out.println("Original author: " + nested.getFrom());
System.out.println("Original subject: " + nested.getSubject());
System.out.println("Files on the original: " + nested.getNumAttachments());
i = i + 1;
}
}
}