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 913901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:37:55+00:00 2026-05-15T17:37:55+00:00

I am working on a project using JavaMail. I want to access my Gmail

  • 0

I am working on a project using JavaMail. I want to access my Gmail inbox and get the messages. I look for a specific message by checking the subject. This message has an attachment which i save.The program works fine on the first run. The problem is that once I run the program, any subsequent runs can not see the message. It does not appear as a part of the folder’s messages. If I go to the gmail account and set “Enable POP for all mail (even mail that’s already been downloaded)” (whihc was the setting from the beginning) I can see the message once more before it again stops appearing in the folder. I dont understand, any help would be great.

Here is my code that gets the messages:

    Session session2 = Session.getDefaultInstance(props2, null);
    Store store = session2.getStore("pop3s");
    store.connect(getHost, username, password);
    Folder folder = store.getFolder("INBOX");
    folder.open(Folder.READ_ONLY);
    System.out.println(folder.getMessageCount());
    Message messages[] = folder.getMessages();
    for (Message message : messages) {
        System.out.println(message.getSubject());
        if (message.getSubject().equalsIgnoreCase("Input File")) {
            if (message.getContent() instanceof Multipart) {
                Multipart multipart = (Multipart) message.getContent();
                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.INLINE))))) {
                        File f = saveFile(part.getFileName(), part.getInputStream());
                        System.out.println(f.getPath());
                    }
                }
            }
        }
    }
    folder.close(false);
    store.close();
}

The saveFile method:

public static File saveFile(String filename, InputStream input) throws FileNotFoundException, IOException {
    File file = new File(filename);
    for (int i = 0; file.exists(); i++) {
        file = new File(filename + i);
    }
    FileOutputStream fos = new FileOutputStream(file);
    BufferedOutputStream bos = new BufferedOutputStream(fos);

    BufferedInputStream bis = new BufferedInputStream(input);
    int aByte;
    while ((aByte = bis.read()) != -1) {
        bos.write(aByte);
    }
    bos.flush();
    bos.close();
    bis.close();
    return file;
}
  • 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-15T17:37:56+00:00Added an answer on May 15, 2026 at 5:37 pm

    I tried switching my code to using imap and now it seems to be working. I guess my problem has something to do with pop3 and gmail.

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

Sidebar

Related Questions

I am working on a project using OpenLayers. And I get the Access is
I am working on a project using iOS3.2 SDK and also want to test
I am working on a project using sinatra with haml for templates. I want
I am working on project using MVC 3.0(Razor framework). I am trying to get
i am working on project using play 2 framework with java. I want to
I'm working on a project using C++. I want a TimerHandler to be called
I'm working on important project using Flex framework and i want to keep my
I'm working on a project using jsp and Microsoft Access. There are three tables
I am working on a project using Visual Studio(c#). I want to create a
Working on a project using Entity Framework (4.3.1.0). I'm trying to figure out how

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.