Creazione e gestione delle opzioni di voto

Microsoft Outlook consente agli utenti di creare un sondaggio durante la composizione di una nuova email, permettendo di includere opzioni di voto come Sì, No, Forse e altro. Allo stesso modo, Aspose.Email offre la funzionalità di creare sondaggi quando si genera un nuovo messaggio Outlook programmaticamente. Il FollowUpOptions classe include la proprietà voting_buttons, che può essere usata per impostare o recuperare le opzioni di voto desiderate.

In questo articolo, esploreremo un esempio dettagliato su come creare un MapiMessage con opzioni di voto per impostare efficacemente un sondaggio.

Crea un sondaggio usando MapiMessage

Per creare un sondaggio, usa la proprietà voting_buttons del FollowUpOptions classe come mostrato nell’esempio di codice sotto:

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")

Leggi opzioni di voto da MapiMessages

Il seguente frammento di codice mostra come leggere le opzioni di voto da un 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)

Leggi solo i pulsanti di voto

Per leggere solo i pulsanti di voto, considera il seguente frammento di codice:

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)

Aggiungi pulsanti di voto ai messaggi esistenti

Il seguente frammento di codice mostra come aggiungere un pulsante di voto a un messaggio esistente:

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")

Elimina pulsanti di voto dai messaggi

Il seguente frammento di codice mostra come eliminare un pulsante di voto da un messaggio:

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")

Leggi informazioni sui risultati di voto

Il seguente frammento di codice mostra come leggere le informazioni sui risultati di voto:

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()}")

Recupera informazioni di reazione da MSG

Il get_reactions metodo del FollowUpManager la classe consente di recuperare l’elenco delle reazioni lasciate su un messaggio MAPI, facilitando l’analisi del coinvolgimento degli utenti. Ogni elemento dell’elenco restituito è un UserReaction oggetto che espone il name, email, type e reaction_date_time proprietà. Il tipo di reazione è un valore del ReactionType enumerazione: LIKE, HEART, CELEBRATE, LAUGH, SURPRISED, SAD oppure UNKNOWN.

Il seguente esempio di codice dimostra come recuperare le reazioni disponibili per un messaggio specifico:

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}")