【问题标题】:Convert EML to MSG - Java将 EML 转换为 MSG - Java
【发布时间】:2018-06-23 13:32:42
【问题描述】:

我想从 EML 文件中读取附件。 .我更喜欢将 EML 文件转换为 MSG 文件,以便我可以重复使用编写的代码,这可能吗?如果没有,有没有办法从 EML 文件中读取附件?

【问题讨论】:

    标签: java aspose msg eml


    【解决方案1】:

    如果没有,有没有办法从 EML 文件中读取附件?

    JavaMail 支持读取 EML 文件(MIME 类型 message/rfc822)。请参阅示例here

    然后提取附件like this。另见this explanation

    【讨论】:

      【解决方案2】:

      您可以使用 Aspose.Email API 来实现 EML 到 MSG 的转换以及从 EML 中提取附件。

      从 EML 中提取附件

      //Initialize and Load an existing EML file
      MailMessage msg = MailMessage.load(dataDir + "EmailWithAttachment.eml", new EmlLoadOptions());
      
      //Initialize AttachmentCollection object with MailMessage Attachments
      AttachmentCollection attachments = msg.getAttachments();
      
      //Iterate over the AttachmentCollection
      for (int index = 0; index < attachments.size(); index++) {
          //Initialize Attachment object and Get the indexed Attachment reference
          Attachment attachment = (Attachment) attachments.get_Item(index);
          //Display Attachment Name
          System.out.println(attachment.getName());
          //Save Attachment to disk
          attachment.save(dataDir + "attachment_" + attachment.getName());
      }
      

      将 EML 转换为 MSG

      // Initialize and Load an existing EML file by specifying the MessageFormat
      MailMessage eml = MailMessage.load(dataDir + "test.eml");
      //Save the Email message to disk in Unicode format
      eml.save(dataDir + "LoadingEMLSavingToMSG_out.msg", SaveOptions.getDefaultMsgUnicode());
      

      您可以进一步访问Working with MIME Messages了解这方面的更多信息。

      我与 Aspose 合作,担任开发人员宣传员。

      【讨论】:

        猜你喜欢
        • 2023-03-14
        • 2015-06-12
        • 2018-11-22
        • 1970-01-01
        • 2016-11-13
        • 1970-01-01
        • 2015-10-27
        • 2011-09-18
        • 2013-02-14
        相关资源
        最近更新 更多