Outlook カレンダー アイテムの管理

この MapiCalendar Aspose.Email ライブラリのクラスは、カレンダーアイテムを構成および操作するためのさまざまなメソッドと属性を提供します。これにより、Outlook カレンダーアイテムの効果的な管理が可能になり、生産性と組織化が向上します。以下のセクションでは、カレンダーアイテム管理のさまざまな側面について案内します。

カレンダー アイテムの作成と保存

カレンダーアイテムの作成と保存

次のコードスニペットは、ICS 形式でカレンダーアイテムを作成し保存する方法を示しています:

  1. カレンダーファイルを保存するパスを定義します。
  2. 新しいものを初期化して予定を作成します MapiCalendar 場所、件名、説明、開始時刻、終了時刻などの特定の詳細を持つオブジェクト。
  3. 作成した予定を指定ディレクトリに ICS ファイルとして保存します。
import aspose.email as ae
from datetime import datetime

data_dir = "path/to/data/directory/"

# Create the appointment
calendar = ae.mapi.MapiCalendar(
    "LAKE ARGYLE WA 6743",
    "Appointment",
    "This is a very important meeting :)",
    datetime(2012, 4, 1),
    datetime(2012, 5, 1))

calendar.save(data_dir + "CalendarItem_out.ics", ae.calendar.AppointmentSaveFormat.ICS)

カレンダーアイテムを MSG として保存

次のコードスニペットは、カレンダーアイテムを MSG として保存する方法を示しています:

import aspose.email as ae
from datetime import datetime

# Create the appointment
calendar = ae.mapi.MapiCalendar(
    "LAKE ARGYLE WA 6743",
    "Appointment",
    "This is a very important meeting :)",
    datetime(2026, 6, 1, 21, 30, 0),
    datetime(2026, 6, 1, 21, 50, 0))

calendar.save(data_dir + "CalendarItem_out.msg", ae.calendar.AppointmentSaveFormat.MSG)

MapiCalendar から ICS 変換のプロダクト ID を設定

Aspose.Email ライブラリを使用すると、MapiCalendar(カレンダーアイテム)を特定のオプションで ICS(iCalendar)ファイルに保存できます。以下は プロパティ これにより、カレンダーアイテムに関連付けられた元の日時スタンプを保持し、ICS ファイルにプロダクト識別子を設定できます。たとえば "Foo Ltd" のように設定します:

  • ics_save_options.keep_original_date_time_stamp
  • ics_save_options.product_identifier

プロダクト識別子は、ICS ファイルを生成したソフトウェアまたはサービスを識別するフィールドです。

以下のコードサンプルは、MapiCalendar を ICS に保存する際にプロダクト ID を設定する方法を示しています:

import aspose.email as ae
from datetime import datetime

mapi_calendar = ae.mapi.MapiCalendar(
    "LAKE ARGYLE WA 6743",
    "Appointment",
    "This is a very important meeting :)",
    datetime(2024, 4, 1),
    datetime(2024, 4, 2))

ics_save_options = ae.mapi.MapiCalendarIcsSaveOptions()
ics_save_options.keep_original_date_time_stamp = True
ics_save_options.product_identifier = "Foo Ltd"

mapi_calendar.save("my.ics", ics_save_options)

カレンダー項目の製品識別子の読み取りと設定

iCalendar ファイルは作成した製品を次に記録します PRODID フィールド。Aspose.Email はカレンダー アイテムが ICS と MSG の間で変換される際にこの識別子を保持するため、アイテムの出所を追跡できます。識別子は次のプロパティで取得可能です:

  • product_id の Appointment クラス - 予定を作成した製品の識別子を取得または設定します。
  • product_id の MapiCalendar クラス - カレンダー アイテムを作成した製品の識別子を取得または設定します。
  • product_identifier の MapiCalendarMsgSaveOptions および MapiCalendarIcsSaveOptions クラス - カレンダー アイテムが保存される際に書き込まれる識別子を設定します。

次のコードサンプルは、ICS ファイルから製品識別子を読み取り、予定を MSG に変換し、 AppointmentMsgSaveOptions、新しい識別子でカレンダー アイテムを保存し、別の識別子を ICS ファイルに書き込みます:

import io
import aspose.email as ae
from aspose.pycore import cast

# Read the product identifier from an iCalendar file
appointment = ae.calendar.Appointment.load("meeting.ics")
print("Appointment product ID:", appointment.product_id)

# The identifier is kept when the appointment is converted to MSG
msg_stream = io.BytesIO()
appointment.save(msg_stream, ae.calendar.AppointmentMsgSaveOptions())
msg_stream.seek(0)
msg = ae.mapi.MapiMessage.load(msg_stream)

if msg.supported_type == ae.mapi.MapiItemType.CALENDAR:
    calendar = cast(ae.mapi.MapiCalendar, msg.to_mapi_message_item())
    print("MapiCalendar product ID:", calendar.product_id)

    # Save the calendar item to MSG with a different product identifier
    options = ae.mapi.MapiCalendarMsgSaveOptions()
    options.product_identifier = "-//Contoso//Calendar 2.0//EN"
    calendar.save("meeting_out.msg", options)

    # The identifier set on the item is written to the PRODID field of an ICS file
    calendar.product_id = "-//Contoso//Calendar 3.0//EN"
    calendar.save("meeting_out.ics", ae.mapi.MapiCalendarIcsSaveOptions())

カレンダーイベントの総数をカウント

この CalendarReader クラスは、指定されたファイルからカレンダーデータを読み取り、分析する機能を提供します。CalendarReader オブジェクトを初期化することで、イベントの総数、カレンダーのバージョン、使用されたメソッド、カレンダーが複数のイベントを含むかどうかなどの重要な詳細を抽出できます。以下は、カレンダーデータとやり取りし、予定を包括的なイベントリストとしてロードする方法を示すコードスニペットです:

import aspose.email as ae

reader = ae.calendar.CalendarReader("calendar.ics")
print(f"Calendar contains {reader.count} events")
print(f"The Version of the calendar is {reader.version}")
print(f"The Method of the calendar is {reader.method}")
print(f"Does the calendar contain multiple events? - {reader.is_multi_events}")
appointments = reader.load_as_multiple()

カレンダーアイテムに表示リマインダーを追加

次のコードスニペットは、カレンダー アイテムに表示リマインダーを追加する方法を示しています:

import aspose.email as ae
from datetime import datetime

# Create the appointment
calendar = ae.mapi.MapiCalendar(
    "LAKE ARGYLE WA 6743",
    "Appointment",
    "This is a very important meeting :)",
    datetime(2026, 6, 1, 21, 30, 0),
    datetime(2026, 6, 1, 21, 50, 0))

calendar.reminder_set = True
calendar.reminder_delta = 45  # 45 minutes before the start of the event

calendar.save(data_dir + "AddDisplayReminderToCalendar_out.ics", ae.calendar.AppointmentSaveFormat.ICS)
calendar.save(data_dir + "AddDisplayReminderToCalendar_out.msg", ae.calendar.AppointmentSaveFormat.MSG)

カレンダーアイテムに音声リマインダーを追加

次のコードスニペットは、カレンダー アイテムに音声リマインダーを追加する方法を示しています:

import aspose.email as ae
from datetime import datetime

# Create the appointment
calendar = ae.mapi.MapiCalendar(
    "LAKE ARGYLE WA 6743",
    "Appointment",
    "This is a very important meeting :)",
    datetime(2026, 6, 1, 21, 30, 0),
    datetime(2026, 6, 1, 21, 50, 0))

calendar.reminder_set = True
calendar.reminder_delta = 45  # 45 minutes before the start of the event
calendar.reminder_file_parameter = "file://Alarm01.wav"

calendar.save(data_dir + "AddAudioReminderToCalendar_out.ics", ae.calendar.AppointmentSaveFormat.ICS)

MapiCalendar の状態を明示的に設定

Aspose.Email は、MapiCalendar オブジェクトの状態を明示的に定義し、デフォルトの動作を上書きするメソッドを提供します:

MapiCalendar オブジェクトが作成されると、状態は自動的に MapiCalendarState.MEETING に割り当てられます。受信者が項目を受け取ると、状態は通常 MapiCalendarState.RECEIVED に変わり、メッセージクラスは "IPM.Schedule.Meeting.Request" に更新されます。

以下のコードサンプルは、Aspose.Email for Python via .NET を使用して会議予定を作成し、主催者とカレンダー状態を手動で設定し、予定を Outlook の .msg ファイルとして保存する方法を示しています。

from aspose.email.mapi import MapiCalendar, MapiCalendarState, MapiElectronicAddress
from aspose.email.calendar import AppointmentSaveFormat
from datetime import datetime, timezone

# Create a MapiCalendar appointment
appointment = MapiCalendar(
    "LAKE ARGYLE WA 6743",                     # Location
    "Appointment",                             # Subject
    "This is a very important meeting :)",     # Body
    datetime(2024, 5, 10, 12, 30, 0, tzinfo=timezone.utc),  # Start time (UTC)
    datetime(2024, 5, 10, 13, 30, 0, tzinfo=timezone.utc)   # End time (UTC)
)

# Set the organizer
appointment.organizer = MapiElectronicAddress()
appointment.organizer.email_address = "test@aaa.com"
appointment.organizer.display_name = "test display Name"

# Forcefully set the calendar state to Meeting | Received
appointment.set_state_forced(MapiCalendarState.MEETING | MapiCalendarState.RECEIVED)

# Save the appointment to a .msg file
appointment.save("appointment.msg", AppointmentSaveFormat.MSG)

呼び出すことで set_state_forced、カレンダー項目の状態を特定の値(例: MapiCalendarState.RECEIVED)に手動で設定できます。これは特に次の場合に便利です:

  • 受信した会議依頼をシミュレートします。

  • 予定を .MSG ファイルに保存する際に、主催者および会議メタデータを保持します。

  • デフォルトの動作が不十分な場合に、カレンダーワークフローをカスタマイズします。

注: 手動で状態を設定するには set_state_forced Outlook の動作に影響を与える可能性があります(会議の転送や再送信機能など)。したがって、注意して使用し、アプリケーションのロジックで必要な場合にのみ使用すべきです。

カレンダーファイル管理

カレンダーファイルから添付ファイルを追加または取得

Aspose.Email カレンダー モジュール (aspose.email.calendar) は添付情報の追加と取得機能も提供します。

予定に添付ファイルを含めるには、以下の手順に従ってください:

  1. 作成します Attachment ファイルパスを提供するオブジェクト。
  2. この添付ファイルを予定の添付リストに追加します。
  3. iCalendar 形式で、特定のファイルパスに予定を保存するには、 保存 メソッドと適切なファイル形式。

予定から添付ファイルを取得するには、次の手順を実行してください:

  1. 保存したファイルから予定をロードするには、 load メソッド。
  2. .attachments.length プロパティを使用して予定の添付ファイル数を取得します。
  3. 各添付ファイルを反復処理します。
  4. ループ内で .name プロパティを使用して各添付ファイルの名前を出力します。

以下のコードスニペットは、添付ファイル付きの予定を作成し、保存し、"ae.calendar" モジュールを使用して添付情報を取得する方法を示しています。カレンダーアプリケーションでの予定と添付ファイルの操作機能と能力を強調しています。

import aspose.email as ae
import datetime as dt

# Add an attachment to an appointment
attendees = ae.MailAddressCollection()
attendees.append(ae.MailAddress("attendee@domain.com", "Recipient 1"))

appointment = ae.calendar.Appointment("Room 112", dt.datetime(2023, 5, 27), dt.date(2023, 5, 28),  ae.MailAddress("organizer@domain.com"), attendees)

attachment = ae.Attachment(data_dir + "Attachment.txt")
appointment.attachments.append(attachment)

appointment.save(data_dir + "appWithAttachments_out.ics", ae.calendar.AppointmentSaveFormat.ICS)

# Retrieve attachments from an appointment 
appointment2 = ae.calendar.Appointment.load(data_dir + "appWithAttachments_out.ics")
print(len(appointment2.attachments))
for att in appointment2.attachments:
    print(att.name)

会議依頼から受信者ステータスを取得

Aspose.Email を使用すると、MapiCalendar オブジェクトとして表現される会議依頼を操作し、会議依頼から受信者のステータス(出席状況)を取得できます。以下のコードスニペットは、各受信者のメールステータスを特定する方法を示しています:

from aspose.email.mapi import MapiMessage

message = MapiMessage.load(data_dir + "MeetingRequest.msg")

for recipient in message.recipients:
    print(f"{recipient.display_name}: {recipient.recipient_track_status}")

EML の予定を MSG に変換し、HTML 本文を保持

Aspose.Email は、EML の予定を MSG に変換しながら HTML 本文を保持することを可能にします。forced_rtf_body_for_appointment プロパティは MapiConversionOptions クラスは予定本文のタイプを操作するために使用されます。True に設定すると、本文はデフォルトで RTF 形式に変換されます。HTML 形式の本文を保持するには、False に設定する必要があります。以下のコードサンプルは、EML から MSG に変換する際に予定の HTML 本文を保持する方法を示しています:

import aspose.email as ae

eml = ae.MailMessage.load("appointment.eml")

conversionOptions = ae.mapi.MapiConversionOptions()
conversionOptions.format = ae.mapi.OutlookMessageFormat.UNICODE
# default value for ForcedRtfBodyForAppointment is true
conversionOptions.forced_rtf_body_for_appointment = False

msg = ae.mapi.MapiMessage.from_mail_message(eml, conversionOptions)

print(f"Body Type: {msg.body_type}")

msg.save("appointment.msg")

予定のリマインダーを設定

予定が作成されるときにリマインダーを追加できます。これらのアラームは、スケジュール開始の n 分前、n 回繰り返し n 間隔で起動するなど、さまざまな条件でトリガーされます。ICS 予定では、これらのトリガーは次のタグで囲まれています。 BEGIN:VALARM および END:VALARM.

リマインダー設定のためにタグを追加

Aspose.Email は、アラーム ブロックを次を通じて公開します。 reminders のコレクション Appointment class と AppointmentReminder, ReminderTrigger, ReminderDuration, ReminderAttachment および ReminderAttendee クラス。アラームの種類は次のもので定義されます。 ReminderAction 列挙型 — AUDIO, DISPLAY, EMAIL または PROCEDURE.

次のコード スニペットは、単一の予定に複数のリマインダーを設定する方法を示しています:

import datetime
import aspose.email as ae
from aspose.email.calendar import (Appointment, AppointmentReminder, ReminderTrigger, ReminderDuration,
                                   ReminderAction, ReminderAttachment, ReminderAttendee, ReminderRelated)

location = "Meeting Location: Room 5"
start_date = datetime.datetime(1997, 3, 18, 18, 30, 0)
end_date = datetime.datetime(1997, 3, 18, 19, 30, 0)

organizer = ae.MailAddress("aaa@amail.com", "Organizer")
attendees = ae.MailAddressCollection()
attendees.append(ae.MailAddress("bbb@bmail.com", "First attendee"))

target = Appointment(location, start_date, end_date, organizer, attendees)

# Audio alarm that will sound at a precise time and repeat 4 more times at 15 minute intervals
audio_reminder = AppointmentReminder()
audio_reminder.trigger = ReminderTrigger(datetime.datetime(1997, 3, 17, 13, 30, 0))
audio_reminder.repeat = 4
audio_reminder.duration = ReminderDuration(datetime.timedelta(minutes=15))
audio_reminder.action = ReminderAction.AUDIO
audio_reminder.attachments.append(ReminderAttachment("ftp://Host.com/pub/sounds/bell-01.aud"))
target.reminders.append(audio_reminder)

# Display alarm that will trigger 30 minutes before the scheduled start of the event
# and will repeat 2 more times at 15 minute intervals
display_reminder = AppointmentReminder()
display_reminder.trigger = ReminderTrigger(ReminderDuration(datetime.timedelta(minutes=-30)), ReminderRelated.START)
display_reminder.repeat = 2
display_reminder.duration = ReminderDuration(datetime.timedelta(minutes=15))
display_reminder.action = ReminderAction.DISPLAY
display_reminder.description = "Breakfast meeting with executive team at 8:30 AM EST"
target.reminders.append(display_reminder)

# Email alarm that will trigger 2 days before the scheduled start. It does not repeat.
email_reminder = AppointmentReminder()
email_reminder.trigger = ReminderTrigger(ReminderDuration(datetime.timedelta(days=-2)), ReminderRelated.START)
email_reminder.attendees.append(ReminderAttendee("john_doe@host.com"))
email_reminder.action = ReminderAction.EMAIL
email_reminder.summary = "REMINDER: SEND AGENDA FOR WEEKLY STAFF MEETING"
email_reminder.description = "A draft agenda needs to be sent out to the attendees of the weekly managers meeting."
email_reminder.attachments.append(ReminderAttachment("http://Host.com/templates/agenda.doc"))
target.reminders.append(email_reminder)

target.save("AppointmentWithReminders_out.ics")

関連項目

  • 繰り返しの管理 — 毎日、毎週、毎月、毎年の MAPI 繰り返しパターンを構築します。