boyeric
asked on
How to read attachments from a MimeMessage using JavaMail?
Hi, dudes! i have a problem concerning JavaMail library, when i want to get attachment files after i acquire messages from the Email server. i've checked up the sun.com online tutorial, they showed me some sample codes like below:
Multipart mp = (Multipart)message.getCont ent();
for (int i=0, n=multipart.getCount(); i<n; i++) {
Part part = multipart.getBodyPart(i));
String disposition = part.getDisposition();
if ((disposition != null) &&
((disposition.equals(Part. ATTACHMENT ) ||
(disposition.equals(Part.I NLINE))) {
saveFile(part.getFileName( ), part.getInputStream());
}
}
But i still have no idea how this "saveFile" method should be written? how can i put the InputStream into the new created file? and do i have to handle the different MimeTypes (.txt, .gif, .zip.....) by myself?
As you may see, i am still new to Java, so will be nice of you to write it in more detail. :) Thanx in advance!
Eric
Multipart mp = (Multipart)message.getCont
for (int i=0, n=multipart.getCount(); i<n; i++) {
Part part = multipart.getBodyPart(i));
String disposition = part.getDisposition();
if ((disposition != null) &&
((disposition.equals(Part.
(disposition.equals(Part.I
saveFile(part.getFileName(
}
}
But i still have no idea how this "saveFile" method should be written? how can i put the InputStream into the new created file? and do i have to handle the different MimeTypes (.txt, .gif, .zip.....) by myself?
As you may see, i am still new to Java, so will be nice of you to write it in more detail. :) Thanx in advance!
Eric
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
you could also use a buffer if you want to read/write chunks at a time