【发布时间】:2018-06-23 13:32:42
【问题描述】:
我想从 EML 文件中读取附件。 .我更喜欢将 EML 文件转换为 MSG 文件,以便我可以重复使用编写的代码,这可能吗?如果没有,有没有办法从 EML 文件中读取附件?
【问题讨论】:
我想从 EML 文件中读取附件。 .我更喜欢将 EML 文件转换为 MSG 文件,以便我可以重复使用编写的代码,这可能吗?如果没有,有没有办法从 EML 文件中读取附件?
【问题讨论】:
如果没有,有没有办法从 EML 文件中读取附件?
JavaMail 支持读取 EML 文件(MIME 类型 message/rfc822)。请参阅示例here。
然后提取附件like this。另见this explanation。
【讨论】:
您可以使用 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 合作,担任开发人员宣传员。
【讨论】: