Aanmaken en beheren van stemopties

Microsoft Outlook stelt gebruikers in staat een poll te maken tijdens het opstellen van een nieuwe e‑mail, waardoor ze stemopties zoals Ja, Nee, Misschien, en meer kunnen opnemen. Evenzo biedt Aspose.Email de functionaliteit om polls te maken bij het programmatisch genereren van een nieuw Outlook‑bericht. De FollowUpOptions klasse bevat de voting_buttons-eigenschap, die kan worden gebruikt om de gewenste stemopties in te stellen of op te halen.

In dit artikel onderzoeken we een gedetailleerd voorbeeld van hoe een MapiMessage met stemopties om effectief een poll in te stellen.

Maak een poll met MapiMessage

Om een poll te maken, gebruik de voting_buttons-eigenschap van de FollowUpOptions klasse zoals weergegeven in het code‑voorbeeld hieronder:

import aspose.email as ae

eml = ae.MailMessage("from@domain.com", "to@domain.com", "Poll", "Please vote")
msg = ae.mapi.MapiMessage.from_mail_message(eml)

# Set the voting buttons
options = ae.mapi.FollowUpOptions()
options.voting_buttons = "Yes;No;Maybe;Exactly!"
ae.mapi.FollowUpManager.set_options(msg, options)

msg.save("voting_btns.msg")

Lees stemopties uit MapiMessages

Het onderstaande code‑fragment toont hoe stemopties te lezen uit een MapiMessage.

from aspose.email.mapi import MapiMessage, FollowUpManager

message = MapiMessage.load(data_dir + "voting_btns.msg")

# This method is useful when, besides the voting buttons, other parameters
# (a category, for example) have to be read as well
options = FollowUpManager.get_options(message)

# The voting buttons are returned as a single string with a semicolon as a separator
print(options.voting_buttons)

Lees alleen stemknoppen

Om alleen stemknoppen te lezen, bekijk het volgende code‑fragment:

from aspose.email.mapi import MapiMessage, FollowUpManager

message = MapiMessage.load(data_dir + "voting_btns.msg")

buttons = FollowUpManager.get_voting_buttons(message)
for button in buttons:
    print(button)

Voeg stemknoppen toe aan bestaande berichten

Het volgende codefragment toont hoe u een stemknop toevoegt aan een bestaand bericht:

from aspose.email.mapi import MapiMessage, FollowUpManager

message = MapiMessage.load(data_dir + "message.msg")

FollowUpManager.add_voting_button(message, "Indeed!")

message.save(data_dir + "AddVotingButtonToExistingMessage_out.msg")

Verwijder stemknoppen uit berichten

Het onderstaande code‑fragment toont hoe een stemknop uit een bericht te verwijderen:

from aspose.email.mapi import MapiMessage, FollowUpManager

message = MapiMessage.load(data_dir + "voting_btns.msg")

# Delete a single button
FollowUpManager.remove_voting_button(message, "Exactly!")

# Or delete all the buttons of the message
FollowUpManager.clear_voting_buttons(message)

message.save(data_dir + "MapiMsgWithoutPoll_out.msg")

Lees stemresultaatinformatie

Het onderstaande code‑fragment toont hoe stemresultaatinformatie te lezen:

from aspose.email.mapi import MapiMessage, MapiPropertyTag

msg = MapiMessage.load(data_dir + "voting_btns.msg")

for recipient in msg.recipients:
    print(f"Recipient: {recipient.display_name}")

    # Get the PR_RECIPIENT_AUTORESPONSE_PROP_RESPONSE property
    if recipient.properties.contains_key(MapiPropertyTag.RECIPIENT_AUTORESPONSE_PROP_RESPONSE):
        response = recipient.properties[MapiPropertyTag.RECIPIENT_AUTORESPONSE_PROP_RESPONSE]
        print(f"Response: {response.get_string()}")

    # Get the PR_RECIPIENT_TRACKSTATUS_TIME property
    if recipient.properties.contains_key(MapiPropertyTag.RECIPIENT_TRACKSTATUS_TIME):
        response_time = recipient.properties[MapiPropertyTag.RECIPIENT_TRACKSTATUS_TIME]
        print(f"Response time: {response_time.get_date_time()}")

Reactie‑informatie uit MSG ophalen

De get_reactions methode van de FollowUpManager klasse stelt je in staat de lijst met reacties op een MAPI‑bericht op te halen, wat de analyse van gebruikersbetrokkenheid vergemakkelijkt. Elk item in de geretourneerde lijst is een UserReaction object dat de name, email, type en reaction_date_time eigenschappen. Het type reactie is een waarde van de ReactionType enumeratie: LIKE, HEART, CELEBRATE, LAUGH, SURPRISED, SAD of UNKNOWN.

De volgende code‑voorbeeld laat zien hoe je de beschikbare reacties voor een opgegeven bericht kunt ophalen:

from aspose.email.mapi import MapiMessage, FollowUpManager

# Load the message file
msg = MapiMessage.load("message.msg")

# Retrieve the list of reactions on the message
reactions = FollowUpManager.get_reactions(msg)

# Iterate through each reaction and output the details
for reaction in reactions:
    print(f"User: {reaction.name}, Email: {reaction.email}, "
          f"Reaction: {reaction.type}, Date: {reaction.reaction_date_time}")