Làm việc với Tùy chọn Bỏ phiếu sử dụng MapiMessage
Tạo tùy chọn Bỏ phiếu bằng MapiMessage
Microsoft Outlook cho phép người dùng tạo một cuộc thăm dò khi soạn tin nhắn mới. Nó cho phép họ bao gồm các tùy chọn bỏ phiếu như Có, Không, Có thể, v.v. Aspose.Email cho phép điều tương tự khi tạo một tin Outlook mới. FollowUpOptions class cung cấp VotingButtons thuộc tính có thể được sử dụng để đặt hoặc lấy giá trị của các tùy chọn bỏ phiếu. Bài viết này cung cấp ví dụ chi tiết về việc tạo một MapiMessage với các tùy chọn bỏ phiếu để tạo một cuộc thăm dò.
Tạo một cuộc thăm dò bằng MapiMessage
Đoạn mã sau đây cho bạn thấy cách tạo một cuộc thăm dò, FollowUpManager lớp có thể được sử dụng như được chỉ ra trong đoạn mã sau.
// 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);
Đọc Các Tùy chọn Bỏ phiếu từ MapiMessage
Đoạn mã sau đây cho bạn thấy cách Đọc các Tùy chọn Bỏ phiếu từ một 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();
Đọc Chỉ Các Nút Bỏ phiếu
Đoạn mã sau đây cho bạn thấy cách chỉ đọc các nút bỏ phiếu.
// 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);
Thêm nút bỏ phiếu vào Tin nhắn hiện có
Đoạn mã sau đây cho bạn thấy cách thêm nút bỏ phiếu vào một tin nhắn hiện có.
// 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");
Xóa Nút Bỏ phiếu khỏi Tin nhắn
Đoạn mã sau đây cho bạn thấy cách xóa nút bỏ phiếu khỏi một tin nhắn.
// 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");
Đọc Thông tin Kết quả Bỏ phiếu
Đoạn mã sau đây cho bạn thấy cách đọc thông tin kết quả bỏ phiếu.
// 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();
}
Các Phương thức Mẫu Được Sử Dụng Trong Các Ví Dụ
Đoạn mã sau đây cho bạn thấy cách tạo một tin nhắn mẫu được sử dụng trong các ví dụ.
// 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;
}