How to convert .eml to .msg in java for free

202 Views Asked by At

Requirement We are calling API..The API need .msg file in request.

Logic I have .eml file in my local diskspace, I want to convert into .msg in java for free. Code Snippet :

String msg_file_path="C:\temp\msg_email.msg";

FileOutputStream msg_file = new FileOutputStream(msg_file_path);

try {

MAPIMessage msgObj = new MAPIMessage("C:\temp\_emai.eml");

msgObj.write(msg_file);

System.out.println("EML file converted to MSG: " + msg_file);

}

catch (Exception e) {

e.printStackTrace();

}

Getting below error:

rg.apache.poi.poifs.filesystem.NotOLE2FileException: Invalid header signature; read 0x6465766965636552, expected 0xE11AB1A1E011CFD0 - Your file appears not to be a valid OLE2 document

1

There are 1 best solutions below

0
Dmitry Streblechenko On

The error is very specific - you are feeding the converter class a text file as if it were MSG. 6465766965636552 is "devieceR", so yes, it is definitely not an MSG file.

Open it in Notepad to see what kind of data you have.