Question

if I save a Message object content to a file using the writeTo method, is it possible recreate the object from that file content?

I know a Message has much more information than the one saved with the writeTo method, like the store, the folder and so on.. but I'm not interested to these information.

Should I parse the file in order to retrieve the information and set every field in a new Message object? Or is there an easier way?

Was it helpful?

Solution

The javax.mail.internet.MimeMessage(Session, InputStream) constructor can be used to parse a MIME message.

try (FileInputStream in = new FileInputStream("foo.eml")) {
        MimeMessage msg = new MimeMessage((Session) null, in);
        //...
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top