การทำงานกับตัวเลือกโหวตและการตอบสนองใน MSG

สร้างตัวเลือกการโหวตด้วย MapiMessage

Microsoft Outlook มีฟีเจอร์ในการสร้างแบบสำรวจเมื่อเขียนอีเมลใหม่ ทำให้ผู้ใช้สามารถรวมตัวเลือกการโหวตเช่น ใช่, ไม่ใช่, ไม่แน่ใจ ฯลฯ Aspose.Email ให้ความสามารถที่คล้ายกันเมื่อสร้างข้อความ Outlook ใหม่โดยอัตโนมัติ. The FollowUpOptions class ให้ VotingButtons คุณสมบัติที่สามารถใช้ตั้งหรือรับค่าตัวเลือกการโหวต. MapiMessage หมายถึงคลาสภายในเนมสเปซ Aspose.Email ที่แสดงถึงข้อความอีเมลในรูปแบบ Messaging Application Programming Interface (MAPI) ที่ Microsoft Outlook ใช้บ่อย โดยการใช้คลาส MapiMessage นักพัฒนาสามารถเพิ่มปุ่มสำรวจลงในอีเมล ได้ บทความนี้ให้ตัวอย่างโดยละเอียดเกี่ยวกับการสร้าง MapiMessage พร้อมตัวเลือกการโหวตเพื่อสร้างแบบสำรวจ.

สร้างแบบสำรวจ

ตัวอย่างโค้ดต่อไปนี้แสดงวิธีสร้างแบบสำรวจในข้อความ Outlook ด้วย Aspose.Email. The 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 ออบเจ็กต์จากข้อความ ซึ่งรวมถึงป/button… (ข้อความต่อเนื่องไม่มีการแปลเพิ่มเติม)
  • 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}");
}