我正在使用 apache 的 MimeMessageParser 来获取 MimeMessage。它还有另一个电子邮件类型附件,其中包含正文内容和内嵌图像。我能够从 mimeMessage 获取电子邮件附件,并且可以成功将其转换为 .msg
文件。
但是当我尝试打开该 .msg
文件时,出现错误
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.
有人可以帮我解决这个问题吗?我想将电子邮件附件转换为 .msg
文件。
以下是我正在使用的代码。
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();
}
最佳答案
我们收到了一位客户发来的电子邮件,其中附加了一些 rfc822 文件。我必须将文件保存到磁盘并将扩展名更改为 eml。之后,我可以在 MS Outlook 中打开电子邮件,然后将其保存为 MSG 格式。
因此,如果您只想打开 rfc822 附件,请使用 eml 扩展名将文件保存在磁盘上,并确保您有一个可以读取这些文件的电子邮件程序。
如果您需要 msg 文件,您必须找到一个转换器来将 eml 转换为 msg。 MS Outlook 还有一个 API,您可以使用它来加载 eml 文件并将其保存到 msg 中。这样您就可以创建自己的转换器。
关于java - 将内容类型 "message/rfc822"的附件转换为 .msg 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56564109/