I am using apache's MimeMessageParser to get a MimeMessage. It has another Email type attachment that has body content and inline images. I was able to fetch the email attachment from mimeMessage and I could convert it to .msg
file successfully.
But when I try to open that .msg
file, an error comes as
We can't open 'C:\local\1_file_ds.msg'. It's possible the file is already open, or you don't have permission to open it.
Can anyone help me with this ? I want to convert the email attachment into .msg
file.
Following is the code that I am using.
List<DataSource> attachmentList = email.getAttachmentList();
int attachmentCount = 1;
try {
for (DataSource attachment : attachmentList) {
if (attachment.getContentType().equals("message/rfc822")) {
InputStream inputStream;
inputStream = attachment.getInputStream();
String destName = "C:\\local\\" + +attachmentCount + "_" + "file_ds" + ".msg";
File file = new File(destName);
FileUtils.copyInputStreamToFile(inputStream, file);
attachmentCount = attachmentCount + 1;
}
}
} catch (IOException e) {
e.printStackTrace();
}