解析 Microsoft Outlook 消息文件

Contents
[ ]

使用 Aspose.Email,您只需几行代码即可解析 Microsoft Outlook 消息。本文展示了具体方法。Aspose.Email 提供了用于处理 Outlook 消息的众多类。下面的代码示例演示了如何:

  1. 加载电子邮件。
  2. 获取邮件主题。
  3. 获取发件人姓名。
  4. 获取完整的邮件正文。
  5. 检查是否存在附件。
  6. 获取所有附件的文件名并保存。

以下代码片段展示了如何解析 Microsoft Outlook 消息文件。

// The path to the File directory and Load Microsoft Outlook email message file
String dataDir = "data/";
MapiMessage msg = MapiMessage.fromFile(dataDir + "message3.msg");

// Obtain subject of the email message, sender, body and Attachment count
System.out.println("Subject:" + msg.getSubject());
System.out.println("From:" + msg.getSenderName());
System.out.println("Body:" + msg.getBody());
System.out.println("Attachment Count:" + msg.getAttachments().size());

// Iterate through the attachments
for (MapiAttachment attachment : msg.getAttachments()) {
    // Access the attachment's file name and Save attachment
    System.out.println("Attachment:" + attachment.getFileName());
    attachment.save(dataDir + attachment.getLongFileName());
}