投票オプションの作成と管理

Microsoft Outlook は新しいメール作成時に投票を作成でき、Yes、No、Maybe などの投票オプションを含めることができます。同様に、Aspose.Email はプログラムで新しい Outlook メッセージを生成する際に投票機能を提供します。 FollowUpOptions クラスには voting_buttons プロパティが含まれ、希望する投票オプションを設定または取得できます。

この記事では、作成方法の詳細な例を探ります。 MapiMessage 投票オプションを設定して投票を効果的に設定します。

MapiMessage を使用した投票の作成

投票を作成するには、voting_buttons プロパティを使用します。 FollowUpOptions 以下のコードサンプルに示すクラスです:

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

MapiMessage から投票オプションを読み取る

以下のコードスニペットは、投票オプションを読み取る方法を示します。 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)

投票ボタンのみを読み取る

投票ボタンのみを読み取るには、以下のコードスニペットを参照してください。

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)

既存メッセージに投票ボタンを追加

次のコードスニペットは、既存のメッセージに投票ボタンを追加する方法を示しています:

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

メッセージから投票ボタンを削除

以下のコードスニペットは、メッセージから投票ボタンを削除する方法を示しています。

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

投票結果情報を読み取る

以下のコードスニペットは、投票結果情報を読み取る方法を示しています。

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

MSG からリアクション情報を取得

この get_reactions メソッド( FollowUpManager クラスは、MAPI メッセージに残されたリアクションのリストを取得できるようにし、ユーザー エンゲージメントの分析を容易にします。返されたリストの各項目は UserReaction オブジェクトが次を公開します。 name, email, type および reaction_date_time プロパティ。リアクション種別は次の値です。 ReactionType 列挙型: LIKE, HEART, CELEBRATE, LAUGH, SURPRISED, SAD または UNKNOWN.

次のコード例は、指定メッセージの利用可能なリアクションを取得する方法を示します:

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