I'm trying to read the content of mail using JavaMail
Object msg = message.getContent();
Multipart mp = (Multipart) msg;
for(int k = 0; k < mp.getCount(); k++) {
BodyPart bp = mp.getBodyPart(k);
if (bp.isMimeType("text/plain")) {
String s = (String) bp.getContent();
System.out.println("Content:" + s);
}
else if(bp.isMimeType("text/html")) {
String s = (String) bp.getContent();
System.out.println("Content:" + s);
}
}
But I'm getting the following error:
java.lang.ClassCastException: java.lang.String cannot be cast to javax.mail.Multipart
How can I remove this?