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 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 project using lxml. here is a sample xml <PatientsTree> <Patient
I'm working under project (using github) with my friend. The situation: My friend checkouted
I'm working chequePrinting project using windows-form, where one of my requirement is to print
I am working on a project using SqlSiteMapProvider. I have two tables Articles and
I'm working on a project using Cufon font replacement, and we're having a rather
I'm working on a project using Java RMI. This is the class causing problem:
I am working on a project using VS2010, WPF, and C#. I used SQL
I was working on some project using webrat and cucumber (rails 3), so I
I've been working on a project using OpenCV for a while, and am ready
Presently, I am working on a project using classic ASP. My development machine is

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.