יצירת וניהול אפשרויות הצבעה
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")
קרא אפשרויות הצבעה מ‑MapiMessages
קטע הקוד הבא מראה כיצד לקרוא אפשרויות הצבעה מ‑ 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 enumeration: 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}")