aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes Mark email as read Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Mark email as read " Watch "Mark email as read " New topic
Author

Mark email as read

Abdoul Kader Soumahoro
Greenhorn

Joined: Aug 28, 2013
Posts: 22
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
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19552
    
  16

Please EaseUp. There is no such thing as "urgent" around here.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Abdoul Kader Soumahoro
Greenhorn

Joined: Aug 28, 2013
Posts: 22
No Problem. I will be patient...
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18150
    
    8

POP3 doesn't support folders. You've already found out that it doesn't support flags much. Why don't you just use IMAP if you need those features?
Abdoul Kader Soumahoro
Greenhorn

Joined: Aug 28, 2013
Posts: 22
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.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39571
    
  27
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.


Ping & DNS - updated with new look and Ping home screen widget
Abdoul Kader Soumahoro
Greenhorn

Joined: Aug 28, 2013
Posts: 22
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
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39571
    
  27
Maybe "copying" isn't the best term for it - you would read the message, and create a text file with its content on your hard disk.
Abdoul Kader Soumahoro
Greenhorn

Joined: Aug 28, 2013
Posts: 22
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...
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18150
    
    8

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.
Abdoul Kader Soumahoro
Greenhorn

Joined: Aug 28, 2013
Posts: 22
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
Abdoul Kader Soumahoro
Greenhorn

Joined: Aug 28, 2013
Posts: 22
I figured it out with the following code:



sentdate is a String here...
Just in case somebody is stuck on this...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Mark email as read
 
Similar Threads
Apache James Server Configuration
pop3 problems on large mailboxes
java mail and Groupwise
where does JavaMail stores received messages?
Can i read my mails of google mail accont (GMAIL) through Java Mail API