투표 옵션 만들기 및 관리

Microsoft Outlook은 새 이메일을 작성하면서 설문을 만들 수 있게 하며, Yes, No, Maybe 등 투표 옵션을 포함할 수 있습니다. 마찬가지로 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}")