cancel
Showing results for 
Search instead for 
Did you mean: 

save incoming msg from pop3 store folder to folder on pc

Former Member
0 Kudos

hello everyone,

I have a problem which in theory should be simple to solve but in practise I can't really seem to figure out how to do it.

Here's the code of how I get the messages to handle each one. What i want to do is put them in a folder on my desktop so I can handle them from there.

(what i do now is get the attachment and save that file alone and deal with it but i'ld like to have the full msg so i can have details on who it's from and who i want to send it to and any other details i might want to process)

Can anyone guide me of how I could do this please?

thanks in advance

Code to connect and get messages:


java.util.Properties props = System.getProperties();

javax.mail.Session session = javax.mail.Session.getInstance(System.getProperties(), null);

javax.mail.Store store = session.getStore("pop3");

store.connect(host, username, password);
javax.mail.Folder folder = store.getFolder("INBOX");

folder.open(javax.mail.Folder.READ_WRITE);

// Get directory
javax.mail.Message messages[] = folder.getMessages();

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

thanks for replying

ok I guess my reply to make it more clear didn't actually help at all so i'll give it one more go and put it in more of a codetelling fashion (meaning it shows what my intentions are but i really don't think it works like this)

previous reply to clarify things:

[basically what I want to do is copy the messages from the javax.mail.Folder to a folder on my desktop as .msg .eml files or whatever they are supposed to be (i don't exactly know but i hope that won't be hard to figure out) so that i can just call for example getFrom on the message file that's been stored in the folder on my desktop.

what i am doing now is getting all the attachments of each message and stick them in a folder on my desktop but most of them need to be replied to and some times more (automatically) and i can't get the details i need just from the attachment and i also don't want to do it one by one while connected to the server cause if the message is big it times out or something, so in order to avoid such problems i want to be able to fully process it on my pc.]

2nd try to make things clearer hehe:

Code to connect and get messages:


java.util.Properties props = System.getProperties();
 
javax.mail.Session session = javax.mail.Session.getInstance(System.getProperties(), null);
 
javax.mail.Store store = session.getStore("pop3");
 
store.connect(host, username, password);
javax.mail.Folder folder = store.getFolder("INBOX");
 
folder.open(javax.mail.Folder.READ_WRITE);
 
// Get directory
javax.mail.Message messages[] = folder.getMessages();

now i was thinking of writing 2 loops (one already exists) one that goes through messages[] and the other other that for each messages<i> i create


File f = new File("temp/" + messages<i>.toString());

and then through some form of reader read from messages<i> somehow and with a writter write it to f.

[i know that it doesn't make sense to read from an array but i can't really think of a better way to demonstrate what i want to do ]

i hope that clears it out a bit let me know if you any other information would be helpful, thanks again for trying

Message was edited by:

Alex Stamatopoulos

former_member182294
Active Contributor
0 Kudos

Hi Alex,

Can you make your requirement more clear? As per my understanding you have fair knowledge on how to handle Java Mail, and your looking for a design in which you have full details about the Message From, Message To and some other details.

Please clarify.

Regards

Abhilash