簡體   English   中英

將內容類型“message/rfc822”的附件轉換為 .msg 文件

[英]Convert an attachment of Content-type "message/rfc822" to .msg file

我正在使用 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();
    }

我們收到了一封來自客戶的電子郵件,他在電子郵件中附加了一些 rfc822 文件。 我不得不將文件保存到磁盤並將擴展名更改為 eml。 之后,我可以在 MS Outlook 中打開電子郵件,然后我可以將其保存為 MSG 格式。

因此,如果您只想打開 rfc822 附件,請將文件以 eml 擴展名保存在磁盤上,並確保您有一個可以讀取這些文件的電子郵件程序。

如果您需要 msg 文件,您必須找到一個轉換器將 eml 轉換為 msg。 此外,MS Outlook 有一個 API,您可以使用它來加載 eml 文件並將其保存到 msg。 這樣您就可以創建自己的轉換器。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM