JavaMail - How do I get the Attachment name and file type

Posted on 2005-04-04
Medium Priority
Last Modified: 2013-11-24
Would anyone give me the idea how to get the attachment name and its file type?

see my code below:

  protected static void handleMultipart(Multipart multipart
                                       ,String    iEmailAttachmentName
                                       ,String    iApplHomeDir
                                       ,String    iEmailSubject
                                       ,String    iIncomingEmailSubject)
      throws MessagingException, IOException {
   try {
    for (int i=0, n=multipart.getCount(); i<n; i++) {
      System.out.println("here u r ****** " + multipart.getBodyPart(i).ATTACHMENT.);
      handlePart(multipart.getBodyPart(i), iEmailAttachmentName, iApplHomeDir,iEmailSubject, iIncomingEmailSubject);
   catch (Throwable e) {
  } // handleMultipart

Question by:LeanMoreTryMore
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
LVL 92

Expert Comment

ID: 13704308
 String filename = multipart.getFileName();
  String contentType = multipart.getContentType();
LVL 92

Accepted Solution

objects earned 1200 total points
ID: 13704321
sorry they should have:

 String filename = part.getFileName();
 String contentType = part.getContentType();

where part is:

Part part = multipart.getBodyPart(i);
LVL 92

Expert Comment

ID: 13704543
should also be useful background:


Featured Post

Linux Academy Android App Now Supports Chromecast

We have some fantastic news for our Android fans. We’re so excited to announce that the Linux Academy Android app is now available with Chromecast support. That’s right – simply download the latest update of the Linux Academy App and start casting your favorite course videos!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month11 days, 11 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question