Working with Voting Option Using MapiMessage

Creating Voting Option Using MapiMessage

Microsoft Outlook lets users create a poll when composing a new message. It lets them include voting options such as Yes, No, Maybe, etc. Aspose.Email allows the same while creating a new Outlook message. The FollowUpOptions class provides the VotingButtons property that can be used to set or get the value of voting options. This article provides a detailed example of creating a MapiMesasge with voting options for creating a poll.

Creating a Poll using MapiMessage

The following code sample shows how to use the voting_buttons property of the FollowUpOptions class to create a poll:

import aspose.email as ae

msg = ae.mapi.MapiMessage.load("my.msg")

# Set FollowUpOptions Buttons
options = ae.mapi.FollowUpOptions()
options.voting_buttons = "Yes;No;Maybe;Exactly!"

msg.save("voting_btns.msg")

Reading Voting Options from a MapiMessage

The following code snippet shows you how to Read Voting Options from a MapiMessage.

For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
message = MapiMessage.from_file("MessageWithVotingResponded.msg")
# This method can be useful when except voting buttons it is necessary to get other parameters (ex. a category)
options = FollowUpManager.get_options(message)
# Voting buttons will be introduced as a string with semi-column as a separator
votingButtons = options.voting_buttons
print(votingButtons)

Reading Only Voting Buttons

The following code snippet shows you how to read only voting buttons.

For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
message = MapiMessage.from_file("MessageWithVotingResponded.msg")
buttons = FollowUpManager.get_voting_buttons(message)
for button in buttons:
print(button)

Adding voting button to an Existing Message

The following code snippet shows you how to add voting button to an existing message.

For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
message = MapiMessage.from_file("message.msg")
FollowUpManager.add_voting_button(message, "Indeed!")
message.save(dataDir + "AddVotingButtonToExistingMessage_out.msg")

Deleting Voting button from a Message

The following code snippet shows you how to delete vote button from a Message.

For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
message = MapiMessage.from_file("message.msg")
FollowUpManager.add_voting_button(message, "Indeed!")
message.save(dataDir + "AddVotingButtonToExistingMessage_out.msg")
eml = MailMessage("from@gmail.com", "to@gmail.com", "Subject", "Body")
eml.is_draft = False
msg = MapiMessage.from_mail_message(eml)
options = FollowUpOptions()
options.voting_buttons = "Yes;No;Maybe;Exactly!"
FollowUpManager.set_options(msg, options)
msg.save(dataDir + "MapiMsgWithPoll.msg")
FollowUpManager.remove_voting_button(msg, "Exactly!");#Deleting a single button OR
FollowUpManager.clear_voting_buttons(msg) # Deleting all buttons from a MapiMessage
msg.save(dataDir + "MapiMsgWithPoll_out.msg")

Read the Vote Results Information

The following code snippet shows you how to read the vote results information.

For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
msg = MapiMessage.from_file(dataDir + "AddVotingButtonToExistingMessage.msg");
for recipient in msg.recipients:
print("Recipient: {0}".format(recipient.display_name))
#get the PR_RECIPIENT_AUTORESPONSE_PROP_RESPONSE property
print("Response: {0}".format(recipient.properties[MapiPropertyTag.RECIPIENT_AUTORESPONSE_PROP_RESPONSE].get_string()))
#Get the PR_RECIPIENT_TRACKSTATUS_TIME property
mt = recipient.properties[MapiPropertyTag.RECIPIENT_TRACKSTATUS_TIME]
if mt is not None:
mt_value = mt.get_date_time()
print("Response time: {}".format(mt_value))

Set unsent message flag

The following code snippet shows you how to how to sample methods used in examples.

import aspose.email as ae

msg = ae.mapi.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...")
msg.set_message_flags(msg.flags ^ ae.mapi.MapiMessageFlags.UNSENT)