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

  • Home
  • SEARCH
  • 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 7085323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:24:38+00:00 2026-05-28T07:24:38+00:00

I am creating Email client using JavaMail API. Everything is working fine like I

  • 0

I am creating Email client using JavaMail API. Everything is working fine like I am able to connect to mail server(using IMAP), Delete mail, retrieving received mails and displaying them to user etc.

Now problem comes when it comes to download “PDF Attachments”. PDF files are not downloading completely… it is missing some contains.

If some PDF attachment is of size 38 Kb when I am downloading attachment using IE or any other web browser but when I am downloading it using my java code it is of size 37.3 Kb. It is not complete
Hence when I try to open it using Adobe Reader it shows error message that “File is corrupted…”

Here is code I have written to download attachment:

public boolean saveFile(String filename,Part part) throws IOException, MessagingException {
    boolean ren = true;
    FileOutputStream fos = null;
    BufferedInputStream fin = null;
    InputStream input = part.getInputStream();

    File pdffile = new File("d:/"+filename);
    try{
        if(!pdffile.exists()){
            fos = new FileOutputStream(pdffile);
            fin = new BufferedInputStream(input);
            int size = 512;
            byte[] buf = new byte[size];
            int len;

            while ( (len = fin.read(buf)) != -1 ) {
                fos.write(buf, 0, len);
            }

            input.close();
            fos.close();
        }else{
            System.out.println("File already exists");
        }
    }catch(Exception e ){
        ren = false;
    }
    return ren;
 }

Am I missing something? Any useful help is appreciated.

  • 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-05-28T07:24:39+00:00Added an answer on May 28, 2026 at 7:24 am

    Finally I found solution at JavaMail FAQ Reading Mail, IMAP section
    Gmail server is running bug with attachments

    First I tried to set partialfetch property false but sometimes it works sometimes it doesn’t

        props.setProperty("mail.imap.partialfetch", "false");
    

    There is another way listed in FAQ which is just use copy constructor of MimeMessage and store orignal object in some tempmsg and then get content of tempmsg

        MimeMessage tempmsg = new MimeMessage(msg);
        Multipart part = (Multipart) tempmsg.getContent();
    

    and now perform all operations it should work..

    For detailed information about what actually happens goto JavaMail FAQ Reading Mail, IMAP section you will find all answers..

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

Sidebar

Related Questions

i am creating an email client that sends e-mail address from server ip instead
i am creating an email client that sends e-mail address from server ip instead
I am creating a web based email client using c# asp.net. What is confusing
I'm creating a web service using PHP5's native SOAP Methods. Everything went fine until
I'm creating an email message using CDO object (and VB6, but that doesn't really
When I'm creating a user for my web application, an SMTP email (using ASP.NET's
I have to add e-mail notifications to a client server application. Notifications happen as
I'm creating a small, web based, mail client in PHP and noticed that a
I am creating email message using Apache James. I add TextBody to message with
I am creating and sending HTML e-mails. I'm using markup like <table style=background: url('http://example.com/App_Sprites/image.gif');>

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.