Hi All,
I am writting an application to read email and display emails using James server and POP3. I would like to know how to move already read email to another folder or how mark these emails as read so that everytime I run the program I will only read new emails. I understand that POP3 makes it a bit complicated because Flags don't really work with POP3 so I'm looking for another alternative to make this work. Please, this is very urgent and adding some code snippet to your answer will help a lot.
Thanks
Since I can get all the message with the follwong Message[] msg = folder.getMessages(); I thought it would be possible to copy and paste these emails (files and attachments) which I believe are stored in the "inbox" folder to another pre defined folder that I create let's say C:\emails and then I can delete the content of the "inbox" folder.
You can of course store emails in some folder on your local hard disk. But that is entirely outside of what JavaMail handles. As Paul said, POP3 doesn't support the concept of folders.
But how can I achieve this? i am stuck when it comes to being able to copy the emails to another folder on my local disk. can anybody help with the code?
Thanks
I used the term "Copy" because I actually want to cpoy the files from the "inbox" folder to another folder on my local disk and then delete the files in the inbox folder. almost like a cut and paste...
When you say "another" folder on your local disk like that, it really sounds like you think that the Inbox folder is also a folder on your local disk. Which it isn't, it's a folder in your mail server. So it would be less confusing if you said you wanted to copy a mail message (please don't call it a "file", that's confusing too) to a file on your local disk.
Let's use that as a description of what you want to do, then. You want to take a message from your mail server (you don't even need to mention the Inbox because POP3 doesn't support folders anyway). And you want to write the message to a file on your disk. (And then you want to delete the message from the mail server.)
If you get the mail message into your code as a MimeMessage then you'll see from the API documentation that there's a writeTo(OutputStream) on that class. You could pass a FileOutputStream to that method. Don't forget to close the output stream after you finish writing to it.
Since moving email after reading is a bit challenging I thought about another alternative. Since after I read an email I store it to a Database I want always want to whether the record exist or not. I believe the combination of Sender and time will always be unique. so I want to check in my table whether this combination exist if yes do not insert but if it exist, insert... But I don't really know how write this logic. can somebody assist whit the code please. Thank you