Outlook 메시지 파일 구문 분석
Contents
[
Hide
]
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());
}
사용해 보세요!
무료로 이메일 파일을 온라인에서 구문 분석하세요 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;
}
}