Java Receive Attachment problem ?
Posted
by
Karthick RM
on Stack Overflow
See other posts from Stack Overflow
or by Karthick RM
Published on 2011-01-04T13:38:10Z
Indexed on
2011/01/04
13:54 UTC
Read the original article
Hit count: 226
Hi to all.I use the following code to download the attachment from the mail .But it gives the ClassCastException on the Multipart declaration
Exception in thread "main" java.lang.ClassCastException: com.sun.mail.imap.IMAPInputStream cannot be cast to javax.mail.Multipart at ReadAttachment.main(ReadAttachment.java:52) How do I handle IMAPInputStream? Thanks in advance !!!
Message messages[] = inbox.getMessages();
for (int j = 0; j < messages.length; j++) {
String mailType = messages[j].getContentType();
System.out.println("------------ Message " + (j + 1)
+ " ------------");
System.out.println("SentDate : " + messages[j].getSentDate());
System.out.println("From : " + messages[j].getFrom()[0]);
System.out.println("Subject : " + messages[j].getSubject());
System.out.println("Type :" + messages[j].getContentType());
System.out.println("Attachment :" + messages[j].getFileName());
Multipart mp = (Multipart) messages[j].getContent();
...........
..............
System.out.println();
}
© Stack Overflow or respective owner