Re: Read Mail From A Folder
Sorry, but saying "this is the problem" or "I can't open that folder" is as useful for us as us saying "then fix the problem" or "then open that folder differently" is useful to you.
What do you mean by each of those things? Are you getting an Exception? Unexpected behavior? Something else? Be specific.
But just glancing at it, you never declare your folder variable. For that matter, what is Folder? I don't see that class in the standard API.
PS- When posting code, make sure you use the code tags.
Re: Read Mail From A Folder
Hello qwert678,
Welcome to the Java Programming Forums.
I have added the highlight tags around your code. For future posts, please use: [highlight=Java] code [/highlight]
I'm not sure if you are aware but you have a missing } at the end of your code. Looking at your path, that is correct.
I will need to import javax.mail before I can look into this any further..
Re: Read Mail From A Folder
OK i've imported javax.mail and the problem is:
The method open(int) in the type Folder is not applicable for the arguments (String)
Check these links:
Folder (JavaMail API documentation)
Java Mail POP3Client Example
Re: Read Mail From A Folder
Another problem is that the folder variable is null. Even if the open() method is given the correct argument, it's still going to cause an NPE.
Re: Read Mail From A Folder
Thank you all for your answers. I wonder if the is another way to open a local folder and reading e-mails?
Thanks in advance
Re: Read Mail From A Folder
What type of files are in this local folder? What extension?
Re: Read Mail From A Folder
the extensions of the files are .eml
Re: Read Mail From A Folder
I found this example online. See if this helps you move forward. Take note of folder.open(Folder.READ_ONLY);
Code Java:
public static void main(String[] args) throws Exception {
URLName server = new URLName("protocol://username:password@host/foldername");
Session session = Session.getDefaultInstance(new Properties(), null);
Folder folder = session.getFolder(server);
if (folder == null) {
System.out.println("Folder " + server.getFile() + " not found.");
System.exit(1);
}
folder.open(Folder.READ_ONLY);
// Get the messages from the server
Message[] messages = folder.getMessages();
for (int i = 0; i < messages.length; i++) {
System.out.println("------------ Message " + (i + 1) + " ------------");
messages[i].writeTo(System.out);
}
folder.close(false);
}