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

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

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

Чтение вариантов голосования из MapiMessage

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

For complete examples and data files, please go to https://github.com/kashifiqb/Aspose.Email-for-C
System::SharedPtr<MapiMessage> message = MapiMessage::FromFile(fileName);
// This method can be useful when except voting buttons it is necessary to get other parameters (ex. a category)
System::SharedPtr<FollowUpOptions> options = FollowUpManager::GetOptions(message);
// Voting buttons will be introduced as a string with semi-column as a separator
System::String votingButtons = options->get_VotingButtons();

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

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

For complete examples and data files, please go to https://github.com/kashifiqb/Aspose.Email-for-C
System::SharedPtr<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
System::ArrayPtr<System::String> buttons = FollowUpManager::GetVotingButtons(testMsg);

Добавление кнопки голосования в существующее сообщение

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

For complete examples and data files, please go to https://github.com/kashifiqb/Aspose.Email-for-C
// The path to the File directory.
System::String dataDir = RunExamples::GetDataDir_Outlook();
System::SharedPtr<MapiMessage> mapi = MapiMessage::FromFile(dataDir + L"message.msg");
FollowUpManager::AddVotingButton(mapi, L"Indeed!");
mapi->Save(dataDir + L"AddVotingButtonToExistingMessage_out.msg");

Удаление кнопки голосования из сообщения

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

For complete examples and data files, please go to https://github.com/kashifiqb/Aspose.Email-for-C
// The path to the File directory.
System::String dataDir = RunExamples::GetDataDir_Outlook();
// Create New Message and set FollowUpOptions, FollowUpManager properties
System::SharedPtr<MapiMessage> msg = CreateTestMessage(false);
System::SharedPtr<FollowUpOptions> options = System::MakeObject<FollowUpOptions>();
options->set_VotingButtons(L"Yes;No;Maybe;Exactly!");
FollowUpManager::SetOptions(msg, options);
msg->Save(dataDir + L"MapiMsgWithPoll.msg");
FollowUpManager::RemoveVotingButton(msg, L"Exactly!");
// Deleting a single button OR
FollowUpManager::ClearVotingButtons(msg);
// Deleting all buttons from a MapiMessage
msg->Save(dataDir + L"MapiMsgWithPoll.msg");

Чтение информации о результатах голосования

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

For complete examples and data files, please go to https://github.com/kashifiqb/Aspose.Email-for-C
System::SharedPtr<MapiMessage> msg = MapiMessage::FromFile(dataDir + L"AddVotingButtonToExistingMessage.msg");
{
auto recipient_enumerator = (msg->get_Recipients())->GetEnumerator();
decltype(recipient_enumerator->get_Current()) recipient;
while (recipient_enumerator->MoveNext() && (recipient = recipient_enumerator->get_Current(), true))
{
System::Console::WriteLine(System::String::Format(L"Recipient: {0}",recipient->get_DisplayName()));
// Get the PR_RECIPIENT_AUTORESPONSE_PROP_RESPONSE property
System::Console::WriteLine(System::String::Format(L"Response: {0}",recipient->get_Properties()->idx_get(MapiPropertyTag::PR_RECIPIENT_AUTORESPONSE_PROP_RESPONSE)->GetString()));
// Get the PR_RECIPIENT_TRACKSTATUS_TIME property
System::Console::WriteLine(System::String::Format(L"Response time: {0}",recipient->get_Properties()->idx_get(MapiPropertyTag::PR_RECIPIENT_TRACKSTATUS_TIME)->GetDateTime()));
System::Console::WriteLine();
}
}