Outlook メッセージファイルの解析
Aspose.Email for Java を使用すると、開発者は Outlook メッセージファイルをロードするだけでなく、内容を解析することもできます。
- ディスクから MSG ファイルをロードするには、次を使用します: MapiMessage 静的クラス Load メソッド。
- MSG ファイルの内容を解析するには、 MapiMessage 多数のメソッドを公開します。
このトピックでは、MSG ファイルをロードして解析し、その内容を表示する方法を示します。
Aspose.Email for Java は、 MapiMessage MSG ファイルを開いて解析するために使用されるクラスです。MSG ファイルには多くの受信者がいる可能性があるため、 MapiMessage クラスは以下を公開します getRecipients() を返すメソッド MapiRecipientCollection は、コレクションを表します MapiRecipient オブジェクト。 MapiRecipient オブジェクトは、受信者属性を操作するための追加メソッドも公開します。
以下の手順がこの目的を果たします:
- インスタンスを作成します MapiMessage MSG ファイルを次からロードするクラス: Load 静的メソッド。
- MSG ファイルから送信者名、件名、本文を次を使用して表示します: getSenderName(), getSubject() および getBody() メソッドです。
- 呼び出す getRecipients() が公開するメソッド MapiRecipient コレクションへの参照を取得するクラス MapiRecipient MSG ファイルに関連付けられたオブジェクト。
- ループで回す MapiRecipientCollection 各項目の内容を表示するコレクション MapiRecipient オブジェクトの公開メソッドを通じて。
// The path to the resource directory.
String dataDir = Utils.getSharedDataDir(ParsingOutlookMessageFiles.class) + "outlook/";
//Instantiate an MSG file to load an MSG file from disk
MapiMessage outlookMessageFile = MapiMessage.fromFile(dataDir + "message.msg");
//Display sender's name
System.out.println("Sender Name : " + outlookMessageFile.getSenderName());
//Display Subject
System.out.println("Subject : " + outlookMessageFile.getSubject());
//Display Body
System.out.println("Body : " + outlookMessageFile.getBody());
//Display Recipient's info
System.out.println("Recipients : \n");
//Loop through the recipients collection associated with the MapiMessage object
for (int i = 0; i < outlookMessageFile.getRecipients().size(); i++) {
//Set a reference to the MapiRecipient object
MapiRecipient rcp = (MapiRecipient) outlookMessageFile.getRecipients().get_Item(i);
//Display recipient email address
System.out.println("Email : " + rcp.getEmailAddress());
//Display recipient name
System.out.println("Name : " + rcp.getDisplayName());
//Display recipient type
System.out.println("Recipient Type : " + rcp.getRecipientType());
}
Try it out!
無料でメールファイルをオンラインで解析 Aspose.Email パーサー アプリ.
MAPI メッセージのアイテムタイプを取得
Aspose.Email は、 MapiItemType アイテムタイプを表す列挙型です。これは、対応するクラスから派生したオブジェクトへのメッセージ変換に使用できます。 IMapiMessageItem インターフェイスです。これにより、ユーザーはメッセージ変換前に MessageClass プロパティの値を確認する必要がなくなります。
以下のコードサンプルは、フォルダー内のメッセージを反復処理し、メッセージの種類に応じて各 MAPI メッセージを対応する MAPI アイテムタイプに変換する方法を示しています。
for (MessageInfo messageInfo : folder.enumerateMessages()) {
MapiMessage msg = pst.extractMessage(messageInfo);
switch (msg.getSupportedType()) {
// Non-supported type. MapiMessage cannot be converted to an appropriate item type.
// Just use in MSG format.
case MapiItemType.None:
break;
// An email message. Conversion isn't required.
case MapiItemType.Message:
break;
// A contact item. Can be converted to MapiContact.
case MapiItemType.Contact:
MapiContact contact = (MapiContact) msg.toMapiMessageItem();
break;
// A calendar item. Can be converted to MapiCalendar.
case MapiItemType.Calendar:
MapiCalendar calendar = (MapiCalendar) msg.toMapiMessageItem();
break;
// A distribution list. Can be converted to MapiDistributionList.
case MapiItemType.DistList:
MapiDistributionList dl = (MapiDistributionList) msg.toMapiMessageItem();
break;
// A Journal entry. Can be converted to MapiJournal.
case MapiItemType.Journal:
MapiJournal journal = (MapiJournal) msg.toMapiMessageItem();
break;
// A StickyNote. Can be converted to MapiNote.
case MapiItemType.Note:
MapiNote note = (MapiNote) msg.toMapiMessageItem();
break;
// A Task item. Can be converted to MapiTask.
case MapiItemType.Task:
MapiTask task = (MapiTask) msg.toMapiMessageItem();
break;
}
}