Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8705401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:21:02+00:00 2026-06-13T03:21:02+00:00

I am using JavaMail to read mail in my Android app. I have tried

  • 0

I am using JavaMail to read mail in my Android app. I have tried to cover all combinations i.e Mail sent/received on/from Custom Server/Gmail ID/Live ID.

The problem occurs with SOME of the mails sent from GMail WITH Attachment. I am able to receive the attachment, but the content returns javax.mail.internet.MimeMultipart@44f2e698

Here’s the code used to receive and read messages:

    Properties props = System.getProperties();
    props.setProperty("mail.store.protocol", "imap");

    try {
     /* Create the session and get the store for read the mail. */
     Session session = Session.getInstance(props, null);
     Store store = session.getStore("imaps");
     store.connect("imap.gmail.com", Username, Password);

     /* Mention the folder name which you want to read. */
     Folder inbox = store.getFolder("INBOX");
     System.out.println("No of Unread Messages : " + inbox.getUnreadMessageCount());         

     /* Open the inbox using store. */
     inbox.open(Folder.READ_ONLY);

     Message messages[] = inbox.getMessages();       
     Log.d("Inbox", "Message Count: "+inbox.getMessageCount());

     for (int i = messages.length - 1 ; i > 0; --i) {
         Log.i("ContentType", "ContentType: "+messages[i].getContentType());

         Object msgContent = messages[i].getContent();

         String content = "";

         /* Check if content is pure text/html or in parts */            
         if (msgContent instanceof Multipart) {

             Multipart multipart = (Multipart) msgContent;

             Log.e("BodyPart", "MultiPartCount: "+multipart.getCount());

             for (int j = 0; j < multipart.getCount(); j++) {

              BodyPart bodyPart = multipart.getBodyPart(j);

              String disposition = bodyPart.getDisposition();

              if (disposition != null && (disposition.equalsIgnoreCase("ATTACHMENT"))) { // BodyPart.ATTACHMENT doesn't work for gmail
                  System.out.println("Mail have some attachment");

                  DataHandler handler = bodyPart.getDataHandler();
                  System.out.println("file name : " + handler.getName());                                 
                }
              else { 
                  System.out.println("Content: "+bodyPart.getContent());
                  content= bodyPart.getContent().toString();
                }
            }
         }
         else                
             content= messages[i].getContent().toString();

What I know about the problematic mails:

  • getFrom also return the name i.e it comes in this format FirstName LastName &ltemailID@gmail.com&gt

  • MultiPart contains 2 BodyParts:

    • BodyPart 1 returns the content as javax.mail.internet.MimeMultipart@44f2e698

    • BodyPart 2 returns the correct name for attachment

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T03:21:03+00:00Added an answer on June 13, 2026 at 3:21 am

    BodyPart 1 returns the content as
    javax.mail.internet.MimeMultipart@44f2e698

    Try calling getBodyPart on the MimeMultiPart

    That probably returns a MimeBodyPart you can call getContent() on
    http://docs.oracle.com/javaee/5/api/javax/mail/internet/MimeBodyPart.html#content

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sending Email in Android using JavaMail API without using the default/built-in app I'm trying
Using JavaMail, I am able to read and download mails from Gmail, but it
I would like to make my android app using my mail server to send
I want to read my emails from ms exchange, I am using java mail
I've written a Java-based standalone program (using JavaMail API) to read email messages from
I am accessing Lotus and Groupwise using javamail via IMAP, recursively accessing all folders
Having to interact with several different email servers via IMAP (using javamail), I have
I am using the JavaMail port for android to send emails without user intervention
I am using IMAP protocol to fetch mails from Google server using java mail.
I am working on an IMAP client using java mail. We currently have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.