Read email text file to convert to Javamail MimeMessage

I have a text file of the original source of the letter (just copied from gmail, if you click "View original", you will see it). I want to read this file and convert it to MimeMessage.

If you are wondering why, I have JavaMaildir and you need to fill in the inbox with email for testing purposes. I never read files and all that, so any help would be greatly appreciated.

+5
source share
1 answer

Something like this should work:

InputStream mailFileInputStream = new FileInputStream(...);
Properties props = new Properties();
Session session = Session.getDefaultInstance(props, null);
MimeMessage message = new MimeMessage(session, mailFileInputStream);
...
+16
source

All Articles