创建和管理投票选项
Contents
[
Hide
]
Microsoft Outlook 允许用户在撰写新邮件时创建投票,能够包含“是”“否”“可能”等投票选项。同样,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}")