【问题标题】:Convert an attachment of Content-type "message/rfc822" to .msg file将 Content-type "message/rfc822" 的附件转换为 .msg 文件
【发布时间】:2019-10-27 01:56:04
【问题描述】:

我正在使用 apache 的 MimeMessageParser 来获取 MimeMessage。它还有另一个 电子邮件 类型的附件,其中包含正文内容和内嵌图像。我能够从 mimeMessage 获取电子邮件附件,并且可以成功地将其转换为 .msg 文件。

但是当我尝试打开 .msg 文件时,出现错误

我们无法打开“C:\local\1_file_ds.msg”。文件可能是 已经打开,或者您没有打开它的权限。

谁能帮我解决这个问题?我想将电子邮件附件转换为.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();
    }

【问题讨论】:

    标签: java mime mime-message rfc822


    【解决方案1】:

    我们收到一封来自客户的电子邮件,该客户在电子邮件中附加了一些 rfc822 文件。我不得不将文件保存到磁盘并将扩展名更改为 eml。之后,我可以在 MS Outlook 中打开电子邮件,然后我可以将其保存为 MSG 格式。

    因此,如果您只想打开 rfc822 附件,请将文件以 eml 扩展名保存在磁盘上,并确保您有一个可以读取这些文件的电子邮件程序。

    如果你需要一个 msg 文件,你必须找到一个转换器来从 eml 转换为 msg。 MS Outlook 也有一个 API,您可以使用它来加载 eml 文件并将其保存到 msg。这样您就可以创建自己的转换器。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-06-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-27
      • 1970-01-01
      • 2020-08-31
      相关资源
      最近更新 更多