MSG における投票オプションとリアクションの操作
MapiMessage で投票オプションを作成
Microsoft Outlook では新規メール作成時に投票(アンケート)機能を提供し、ユーザーは「はい」「いいえ」「未定」などの投票オプションを含めることができます。Aspose.Email はプログラムで新しい Outlook メッセージを作成する際に同様の機能を提供します。 FollowUpOptions class は以下を提供します VotingButtons 投票オプションを設定または取得できるプロパティです。 MapiMessage Aspose.Email 名前空間内のクラスで、Microsoft Outlook が一般的に使用するメッセージング アプリケーション プログラミング インターフェイス (MAPI) 形式のメール メッセージを表します。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}");
}