• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Mark email as read

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please EaseUp. There is no such thing as "urgent" around here.
 
Abdoul Kader Soumahoro
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No Problem. I will be patient...
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Abdoul Kader Soumahoro
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I figured it out with the following code:



sentdate is a String here...
Just in case somebody is stuck on this...
reply
    Bookmark Topic Watch Topic
  • New Topic