การทำงานกับตัวเลือกโหวตโดยใช้ MapiMessage

สร้างตัวเลือกโหวตโดยใช้ MapiMessage

Microsoft Outlook ให้ผู้ใช้สร้างโพลขณะเขียนข้อความใหม่ สามารถใส่ตัวเลือกโหวตเช่น ใช่, ไม่ใช่, อาจจะ เป็นต้น 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;
}