Работа с вариантами голосования с помощью MapiMessage

Создание варианта голосования с помощью MapiMessage

Microsoft Outlook позволяет пользователям создавать опрос при составлении нового сообщения. Он позволяет им включать варианты голосования, такие как Да, Нет, Может быть и т.д. Aspose.Email предлагает аналогичные возможности при создании нового сообщения Outlook. Класс FollowUpOptions предоставляет свойство VotingButtons, которое можно использовать для установки или получения значения вариантов голосования. Эта статья представляет собой подробный пример создания MapiMessage с вариантами голосования для создания опроса.

Создание опроса с помощью MapiMessage

Следующий код показывает, как создать опрос, класс FollowUpManager можно использовать, как показано в следующем коде.

// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET
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.VotingButtons = "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-.NET
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.VotingButtons;

Чтение только кнопок голосования

Следующий код показывает, как читать только кнопки голосования.

// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET
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-.NET
// The path to the File directory.
string dataDir = RunExamples.GetDataDir_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-.NET
// The path to the File directory.
string dataDir = RunExamples.GetDataDir_Outlook();
// Create New Message and set FollowUpOptions, FollowUpManager properties
MapiMessage msg = CreateTestMessage(false);
FollowUpOptions options = new FollowUpOptions();
options.VotingButtons = "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-.NET
MapiMessage msg = MapiMessage.FromFile(dataDir + @"AddVotingButtonToExistingMessage.msg");
foreach (MapiRecipient recipient in msg.Recipients)
{
Console.WriteLine(string.Format("Recipient: {0}", recipient.DisplayName));
// Get the PR_RECIPIENT_AUTORESPONSE_PROP_RESPONSE property
Console.WriteLine(string.Format("Response: {0}", recipient.Properties[MapiPropertyTag.PR_RECIPIENT_AUTORESPONSE_PROP_RESPONSE].GetString()));
// Get the PR_RECIPIENT_TRACKSTATUS_TIME property
Console.WriteLine(string.Format("Response time: {0}", recipient.Properties[MapiPropertyTag.PR_RECIPIENT_TRACKSTATUS_TIME].GetDateTime()));
Console.WriteLine();
}

Методы примерa, используемые в примерах

Следующий код показывает, как создать тестовое сообщение, использованное в примерах.

// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET
private static MapiMessage CreateTestMessage(bool 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.Flags ^ MapiMessageFlags.MSGFLAG_UNSENT);
}
return msg;
}