在 MSG 中使用投票选项和反应
使用 MapiMessage 创建投票选项
Microsoft Outlook 在撰写新电子邮件时提供创建投票的功能,允许用户包含“是”“否”“可能”等投票选项。Aspose.Email 在以编程方式创建新的 Outlook 邮件时提供了类似的功能。 FollowUpOptions class 提供了 VotingButtons 可用于设置或获取投票选项的属性。 MapiMessage 指的是 Aspose.Email 命名空间中的一个类,它表示在消息应用程序编程接口 (MAPI) 格式(Microsoft Outlook 常用)的电子邮件。通过使用 MapiMessage 类,开发者可以在电子邮件中添加投票按钮。本文提供了如何创建带有投票选项的 MapiMessage 以生成投票的详细示例。
创建投票
以下代码片段演示了如何使用 Aspose.Email 在 Outlook 邮件中创建投票。 FollowUpManager 类可帮助设置投票选项。
// Create a MapiMessage with the sender, recipient, subject, and body
var msg = new 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..."
);
// Create FollowUpOptions and set the voting buttons
var options = new FollowUpOptions
{
VotingButtons = "Yes;No;Maybe;Exactly!"
};
// Apply the follow-up options to the message
FollowUpManager.SetOptions(msg, options);
- FollowUpOptions: 提供用于配置后续操作(如投票按钮)的属性。
- VotingButtons:字符串属性,不同的投票选项用分号分隔。
- FollowUpManager.SetOptions:将指定的后续选项应用于消息。
读取投票选项
要从中检索投票选项,您可以使用 MapiMessage,您可以使用 GetOptions 方法。此方法不仅检索投票按钮,还可在必要时提供诸如类别等额外参数。
// Retrieve follow-up options from the message
var options = FollowUpManager.GetOptions(msg);
// Voting buttons are returned as a string with a semicolon separator
string votingButtons = options.VotingButtons;
// Display the voting buttons
Console.WriteLine($"Voting Options: {votingButtons}");
- GetOptions:检索 FollowUpOptions 来自消息的对象,其中包括投票按钮以及可能的其他属性。
- VotingButtons:这些选项提取为分号分隔的字符串,便于显示或操作。
读取投票按钮
如果您只需要将投票按钮作为单独字符串的列表访问,可以使用以下方式: GetVotingButtons 方法,返回它们的集合。
// Read only voting buttons as a collection of string values
var votingButtons = FollowUpManager.GetVotingButtons(msg);
// Display each voting button
foreach (var button in votingButtons)
{
Console.WriteLine($"Voting Button: {button}");
}
- GetVotingButtons:返回投票按钮字符串的集合,便于遍历它们并执行诸如显示或修改的操作。
添加投票按钮
您可以使用以下方式向现有消息添加额外的投票按钮: AddVotingButton 方法。这对于动态更新投票选项很有用。
// Add a new voting button to the existing message
FollowUpManager.AddVotingButton(msg, "Indeed!");
- AddVotingButton:向消息现有的投票按钮添加新投票选项,允许对投票进行动态自定义。
删除投票按钮
您可能想要删除消息中的特定投票按钮或清除所有按钮。下面的代码演示了使用以下方式执行这两种操作: RemoveVotingButton 和 ClearVotingButtons 方法。
// Delete a specific voting button
FollowUpManager.RemoveVotingButton(msg, "Exactly!");
// Or delete all voting buttons from the MapiMessage
FollowUpManager.ClearVotingButtons(msg);
- RemoveVotingButton:按名称删除特定投票按钮。
- ClearVotingButtons:移除所有投票按钮,实质上重置投票选项。
读取投票结果
Aspose.Email 还允许读取消息收件人的投票结果。您可以访问如收件人响应和响应时间等属性。
// Load a MapiMessage from a file
var msg = MapiMessage.Load("sample.msg");
// Iterate through each recipient and display their vote information
foreach (var recipient in msg.Recipients)
{
Console.WriteLine($"Recipient: {recipient.DisplayName}");
// Get the recipient's response using the appropriate MapiPropertyTag
var response = recipient.Properties[MapiPropertyTag.PR_RECIPIENT_AUTORESPONSE_PROP_RESPONSE].GetString();
Console.WriteLine($"Response: {response}");
// Get the response time
var responseTime = recipient.Properties[MapiPropertyTag.PR_RECIPIENT_TRACKSTATUS_TIME].GetDateTime();
Console.WriteLine($"Response time: {responseTime}\n");
}
- MapiRecipient:表示 MapiMessage 中的收件人,允许访问各自的响应数据。
- *PR_RECIPIENT_AUTORESPONSE_PROP_RESPONSE:存储收件人投票响应的属性标签。
- PR_RECIPIENT_TRACKSTATUS_TIME:记录收件人响应时间的属性标签。
从 MSG 检索反应信息
该 GetReactions 方法的 FollowUpManager 该类允许您检索 MAPI 消息的反应列表,便于分析用户参与度。下面的代码示例演示了如何检索指定消息的可用反应,从而洞察用户互动情况:
// Load the message file
var msg = MapiMessage.Load(fileName);
// Retrieve the list of reactions on the message
var reactions = FollowUpManager.GetReactions(msg);
// Iterate through each reaction and output the details to the console
foreach (var reaction in reactions)
{
Console.WriteLine($"User: {reaction.Name}, Email: {reaction.Email}, Reaction: {reaction.Type}, Date: {reaction.ReactionDateTime}");
}