MapiMessage를 사용한 투표 옵션 작업

MapiMessage를 사용한 투표 옵션 만들기

Microsoft Outlook은 새 메시지를 작성할 때 사용자가 설문을 만들 수 있게 합니다. Yes, No, Maybe 등과 같은 투표 옵션을 포함할 수 있습니다. Aspose.Email도 새로운 Outlook 메시지를 만들 때 동일한 기능을 제공합니다. FollowUpOptions class는 다음을 제공합니다 VotingButtons 투표 옵션 값을 설정하거나 가져오는 데 사용할 수 있는 속성입니다. 이 문서는 설문을 만드는 자세한 예제를 제공합니다. MapiMessage 설문 작성을 위한 투표 옵션과 함께.

MapiMessage를 사용한 설문 만들기

다음 코드 스니펏은 설문을 만드는 방법을 보여줍니다. FollowUpManager 클래스는 다음 코드 스니펏에 표시된 대로 사용할 수 있습니다.

// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
String address = "firstname.lastname@aspose.com";
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain");
MailMessage message = createTestMessage(address);

// Set FollowUpOptions Buttons
FollowUpOptions options = new FollowUpOptions();
options.setVotingButtons("Yes;No;Maybe;Exactly!");
client.send(message, options);

MapiMessage에서 투표 옵션 읽기

다음 코드 스니펏은 다음에서 투표 옵션을 읽는 방법을 보여줍니다 MapiMessage.

// 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 fileName = "outlook/message.msg";

MapiMessage message = MapiMessage.fromFile(fileName);

// This method can be useful when except voting buttons it is necessary to get other parameters (ex. a category)
FollowUpOptions options = FollowUpManager.getOptions(message);

// Voting buttons will be introduced as a string with semi-column as a separator
String votingButtons = options.getVotingButtons();

투표 버튼만 읽기

다음 코드 스니펏은 투표 버튼만 읽는 방법을 보여줍니다.

// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
InputStream ms = new FileInputStream(dataDir + "MapiMsgWithPoll_out.msg");
MapiMessage testMsg = MapiMessage.fromStream(ms);

// This method can be useful when it is necessary to read only voting buttons
// Voting buttons will be introduced as a collection of string values
IList buttons = FollowUpManager.getVotingButtons(testMsg);

기존 메시지에 투표 버튼 추가

다음 코드 스니펏은 기존 메시지에 투표 버튼을 추가하는 방법을 보여줍니다.

// 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 mapi = MapiMessage.fromFile(dataDir + "message.msg");
FollowUpManager.addVotingButton(mapi, "Indeed!");
mapi.save(dataDir + "AddVotingButtonToExistingMessage_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/";

// Create New Message and set FollowUpOptions, FollowUpManager properties
MapiMessage msg = createTestMessage(false);

FollowUpOptions options = new FollowUpOptions();
options.setVotingButtons("Yes;No;Maybe;Exactly!");
FollowUpManager.setOptions(msg, options);
msg.save(dataDir + "MapiMsgWithPoll.msg");
FollowUpManager.removeVotingButton(msg, "Exactly!"); // Deleting a single button OR
FollowUpManager.clearVotingButtons(msg); // Deleting all buttons from a MapiMessage
msg.save(dataDir + "MapiMsgWithPoll.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 msg = MapiMessage.fromFile(dataDir + "AddVotingButtonToExistingMessage.msg");
for (MapiRecipient recipient : msg.getRecipients()) {
    System.out.println("Recipient: " + recipient.getDisplayName());

    // Get the PR_RECIPIENT_AUTORESPONSE_PROP_RESPONSE property
    System.out.println("Response: " + recipient.getProperties().get_Item(MapiPropertyTag.PR_RECIPIENT_AUTORESPONSE_PROP_RESPONSE).getString());

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

    System.out.println();
}

예제에서 사용된 샘플 메서드

다음 코드 스니펫은 예제에서 사용되는 샘플 메시지를 만드는 방법을 보여줍니다.

// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
public static MapiMessage createTestMessage(boolean draft) {
    MapiMessage msg = new MapiMessage("from@test.com", "to@test.com", "Flagged message",
            "Make it nice and short, but descriptive. The description may appear in search engines' search results pages...");

    if (!draft) {
        msg.setMessageFlags(msg.getFlags() ^ MapiMessageFlags.MSGFLAG_UNSENT);
    }
    return msg;
}