Aspose.Email.Outlook을 사용한 메시지 파일 관리

MSG를 MIME 메시지로 변환

Aspose.Email API는 다음을 사용하여 MSG 파일을 MIME 메시지로 변환하는 기능을 제공합니다. toMailMessage 메서드.

// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
MapiMessage msg = new MapiMessage(
                            "sender@test.com",
                            "recipient1@test.com; recipient2@test.com",
                            "Test Subject",
                            "This is a body of message.");
MailConversionOptions options = new MailConversionOptions();
options.setConvertAsTnef(true);
MailMessage mail = msg.toMailMessage(options);

MSG를 EML로 변환하면서 RTF 본문 보존

API는 MSG를 EML로 변환하는 동안 RTF 본문을 보존하기 위한 다음 메서드를 제공합니다:

다음 코드 샘플은 MailMessage에서 RTF 본문을 유지하는 방법을 보여줍니다:

MsgLoadOptions options = new MsgLoadOptions();
options.setPreserveRtfContent(true);
MailMessage message = MailMessage.load("fileName", options);
MapiMessage mapi = MapiMessage.load("fileName");
MailConversionOptions options = new MailConversionOptions();
options.setPreserveRtfContent(true);
MailMessage message = mapi.toMailMessage(options);

카테고리 헤더를 보존하면서 MSG를 MHTML로 변환

Aspose.Email API는 메시지를 MHTML로 변환할 때 카테고리 헤더를 추가할 수 있는 기능을 제공합니다. 이 기능은 다음에 의해 지정됩니다. MhtSaveOptions MailMessage를 MHTML 형식으로 저장할 때 추가 옵션으로 사용되는 클래스.

다음 코드 샘플은 MapiMessage 객체에서 MHT(MHTML) 파일을 생성하고, MhtSaveOptions를 사용해 MHT 파일의 서식 및 헤더를 맞춤 설정하며, 이메일 메시지에 카테고리를 설정한 뒤 저장하기 전에 MHT 파일의 형식 템플릿과 렌더링 헤더를 수정하는 방법을 보여줍니다.

 MapiMessage msg = new MapiMessage("from@aaa.com", "to@aaa.com", "subj", "body");

msg.setCategories(new String[] { "Urgently", "Important" });

MhtSaveOptions saveOptions = new MhtSaveOptions();

saveOptions.getFormatTemplates().set_Item(MhtTemplateName.CATEGORIES,

    saveOptions.getFormatTemplates().get_Item(MhtTemplateName.CATEGORIES).replace("Categories", "Les catégories"));

saveOptions.getRenderingHeaders().add(MhtTemplateName.CATEGORIES);

msg.save("fileName.mhtml", saveOptions);

Outlook 템플릿 파일(.OFT) 읽기 및 쓰기

Outlook 템플릿은 유사한 이메일을 반복해서 보낼 때 매우 유용합니다. 매번 처음부터 메시지를 준비하는 대신, 먼저 Outlook에서 메시지를 작성하고 Outlook 템플릿(OFT)으로 저장합니다. 이후 메시지를 보내야 할 때마다 템플릿을 사용해 만들 수 있어 본문이나 제목에 동일한 텍스트를 작성하고 서식을 설정하는 데 드는 시간을 절약할 수 있습니다. Aspose.Email MailMessage 클래스를 사용하여 Outlook 템플릿(OFT) 파일을 로드하고 읽을 수 있습니다. Outlook 템플릿이 해당 인스턴스에 로드되면 MailMessage 클래스를 사용하면 발신자, 수신자, 본문, 제목 및 기타 속성을 업데이트할 수 있습니다. 속성을 업데이트한 후:

  • 다음으로 이메일을 보냅니다 SmtpClient 클래스 또는
  • 메시지를 MSG로 저장하고 Microsoft Outlook을 사용하여 추가 업데이트/검증을 수행합니다.

아래 코드 예시에서 우리는:

  1. 다음으로 템플릿을 로드합니다 MailMessage 클래스.
  2. 몇몇 속성을 업데이트합니다.
  3. 메시지를 MSG 형식으로 저장합니다.

다음 코드 스니펫은 OFT 파일을 로드하고, 메시지를 업데이트한 후 MSG 형식으로 저장하는 방법을 보여줍니다.

// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
// The path to the File directory.
String dataDir = "outlook/";

// Load the Outlook template (OFT) file in MailMessage's instance
MailMessage message = MailMessage.load(dataDir + "sample.oft", new MsgLoadOptions());

// Set the sender and recipients information
String senderDisplayName = "John";
String senderEmailAddress = "john@abc.com";
String recipientDisplayName = "William";
String recipientEmailAddress = "william@xzy.com";

message.setSender(new MailAddress(senderEmailAddress, senderDisplayName));
message.getTo().addMailAddress(new MailAddress(recipientEmailAddress, recipientDisplayName));
message.setHtmlBody(message.getHtmlBody().replace("DisplayName", "<b>" + recipientDisplayName + "</b>"));

// Set the name, location and time in email body
String meetingLocation = "<u>" + "Hall 1, Convention Center, New York, USA" + "</u>";
String meetingTime = "<u>" + "Monday, June 28, 2010" + "</u>";
message.setHtmlBody(message.getHtmlBody().replace("MeetingPlace", meetingLocation));
message.setHtmlBody(message.getHtmlBody().replace("MeetingTime", meetingTime));

// Save the message in MSG format and open in Office Outlook
MapiMessage mapimessage = MapiMessage.fromMailMessage(message);
mapimessage.setMessageFlags(MapiMessageFlags.MSGFLAG_UNSENT);
mapimessage.save(dataDir + "ReadAndWritingOutlookTemplateFile_out.msg");

Outlook MSG 파일을 템플릿으로 저장

다음 코드 스니펫은 Outlook MSG 파일을 템플릿으로 저장하는 방법을 보여줍니다.

// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
// The path to the File directory.
String dataDir = "outlook/";

try (MapiMessage mapi = new MapiMessage("test@from.to", "test@to.to", "template subject", "Template body")) {
    mapi.saveAsTemplate(dataDir + "mapiToOft.msg");
}

Outlook MSG 파일에 색상 카테고리 설정

색상 카테고리는 이메일 메시지에 특정 중요도나 범주를 표시합니다. Microsoft Outlook에서는 사용자가 색상 카테고리를 할당하여 이메일을 구분할 수 있습니다. 색상 카테고리를 처리하려면 다음을 사용하십시오 FollowUpManager. 다음과 같은 함수들을 포함합니다 addCategory, removeCategory, clearCategories 및 getCategories.

  • addCategory 받습니다 MapiMessage 그리고 색상 카테고리 문자열을 인수로 사용합니다. 예: "Purple Category" 또는 "Red Category".
  • removeCategory 받습니다 MapiMessage 그리고 메시지에서 제거할 색상 카테고리 문자열입니다.
  • clearCategories 메시지에서 모든 색상 카테고리를 제거하는 데 사용됩니다.
  • getCategories 특정 메시지에서 모든 색상 카테고리를 검색하는 데 사용됩니다.

다음 예제는 아래와 같이 작업을 수행합니다:

  1. 색상 카테고리를 추가합니다.
  2. 다른 색상 카테고리를 추가합니다.
  3. 모든 카테고리의 목록을 검색합니다.
  4. 모든 카테고리를 제거합니다.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
// The path to the File directory.
String dataDir = "outlook/";

MapiMessage msg = MapiMessage.fromFile(dataDir + "message.msg");

// Add Two category
FollowUpManager.addCategory(msg, "Purple Category");
FollowUpManager.addCategory(msg, "Red Category");

// Retrieve the list of available categories
IList categories = FollowUpManager.getCategories(msg);

// Remove the specified category and then Clear all categories
FollowUpManager.removeCategory(msg, "Red Category");
FollowUpManager.clearCategories(msg);

MSG 파일에서 후속 정보 액세스

Aspose.Email API는 보낸 또는 받은 메시지에서 후속 정보를 액세스할 수 있는 기능을 제공합니다. 메시지 파일에서 읽음, 배달 영수증 및 투표 결과 정보를 검색할 수 있습니다.

읽음 및 배달 영수증 정보 가져오기

다음 코드 스니펫은 읽음 및 배달 영수증 정보를 검색하는 방법을 보여줍니다.

// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
// The path to the File directory.
String dataDir = "outlook/";

MapiMessage msg = MapiMessage.fromFile(dataDir + "message.msg");
for (MapiRecipient recipient : msg.getRecipients()) {
    System.out.println("Recipient: " + recipient.getDisplayName());

    // Get the PR_RECIPIENT_TRACKSTATUS_TIME_DELIVERY property
    System.out.println("Delivery time: " + recipient.getProperties().get_Item(MapiPropertyTag.PR_RECIPIENT_TRACKSTATUS_TIME_DELIVERY).getDateTime());

    // Get the PR_RECIPIENT_TRACKSTATUS_TIME_READ property
    System.out.println("Read time" + recipient.getProperties().get_Item(MapiPropertyTag.PR_RECIPIENT_TRACKSTATUS_TIME_READ).getDateTime());
}

전달 및 회신 메시지 만들기

Aspose.Email API는 전달 및 회신 메시지를 만들고 포맷팅하는 기능을 제공합니다. 해당 ReplyMessageBuilderForwardMessageBuilder API의 클래스는 각각 회신 및 전달 메시지를 만드는 데 사용됩니다. 회신 또는 전달 메시지는 다음 모드 중 任意 하나를 사용해 생성하도록 지정할 수 있습니다. OriginalMessageAdditionMode 열거형. 이 열거형은 다음 값을 가집니다:

  • OriginalMessageAdditionMode.None - 원본 메시지가 응답 메시지에 포함되지 않습니다.
  • OriginalMessageAdditionMode.Attachment - 원본 메시지가 응답 메시지에 첨부 파일로 포함됩니다
  • OriginalMessageAdditionMode.Textpart - 원본 메시지가 응답 메시지 본문에 텍스트로 포함됩니다

회신 메시지 만들기

다음 코드 조각은 회신 메시지를 만드는 방법을 보여줍니다.

// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
// The path to the File directory.
String dataDir = "outlook/";

MapiMessage originalMsg = MapiMessage.fromFile(dataDir + "message1.msg");
ReplyMessageBuilder builder = new ReplyMessageBuilder();

// Set ReplyMessageBuilder Properties
builder.setReplyAll(true);
builder.setAdditionMode(OriginalMessageAdditionMode.Textpart);
builder.setResponseText(
        "<p><b>Dear Friend,</b></p> I want to do is introduce my co-author and co-teacher. <p><a href=\"www.google.com\">This is a first link</a></p><p><a href=\"www.google.com\">This is a second link</a></p>");

MapiMessage replyMsg = builder.buildResponse(originalMsg);
replyMsg.save(dataDir + "reply_out.msg");

전달 메시지 만들기

다음 코드 조각은 전달 메시지를 만드는 방법을 보여줍니다.

// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
// The path to the File directory.
String dataDir = "outlook/";

MapiMessage originalMsg = MapiMessage.fromFile(dataDir + "message1.msg");
ForwardMessageBuilder builder = new ForwardMessageBuilder();
builder.setAdditionMode(OriginalMessageAdditionMode.Textpart);
MapiMessage forwardMsg = builder.buildResponse(originalMsg);
forwardMsg.save(dataDir + "forward_out.msg");

메시지 변환 시 빈 날짜 보존

MapiConversionOptions.setPreserveEmptyDates(boolean) 메시지를 변환할 때 빈 날짜를 유지해야 하는지를 나타내는 속성. 이 API는 Aspose.Email 21.5에 등장했습니다. 다음 코드 조각은 빈 날짜를 보존하는 방법을 보여줍니다.

MailMessage mailMessage = MailMessage.load("message.eml");
System.out.println(mailMessage.getDate()); // zero date
MapiConversionOptions mco = MapiConversionOptions.getUnicodeFormat();
// keep empty dates when converting a message
mco.setPreserveEmptyDates(true);
MapiMessage mapiMessage = MapiMessage.fromMailMessage(mailMessage, mco);
System.out.println(mapiMessage.getClientSubmitTime()); // zero date
// check zero date
if (mapiMessage.getClientSubmitTime().equals(JavaHelper.ZERO_DATE))
    System.out.println("ZERO DATE");