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
  • 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

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses
Course of the Month9 days, 17 hours left to enroll

569 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