Reputation: 21
code snippet for writing files-
ObjectOutputStream objOut = new ObjectOutputStream(new
FileOutputStream(new File("inboxEmails.eml"))
for (Message message : messages) {
message.writeTo(objOut);
System.out.println("Writing to file");
}
}
messages is an array with over 30 messages.
Retrieval -
Properties props = new Properties();
props.setProperty("mail.store.protocol", "imaps");
Session session = Session.getDefaultInstance(props, null);
InputStream source = inboxFile;
MimeMessage message = new MimeMessage(session, source);
This gets me only one message. I want to retrieve all the messages (30) in an object list.
Upvotes: 0
Views: 887
Reputation: 29981
Normally a .eml file contains only a single message. If you're going to write more than one message to a single file, that file effectively becomes a folder holding multiple messages, and you need to do something to separate the messages, and then you need to examine this separation and present the MimeMessage constructor with an InputStream that respects this separation. The most common way to do this is using the UNIX mbox format as supported by the JavaMail mbox provider.
Upvotes: 1