Outlook カレンダー アイテムの管理
この記事では、Outlook を取り上げます MapiCalendar MSG として保存されたカレンダー アイテム。標準ベースの iCalendar (ICS) の予定と会議リクエストを操作するには、こちらをご覧ください 予定の管理; PST 内のカレンダー アイテムを保存および読み取る方法については、こちらをご覧ください PST ファイル内のカレンダー アイテムの管理.
Aspose.Email MapiCalendar クラスはカレンダーアイテムのさまざまなプロパティを設定するメソッドと属性を提供します。このセクションでは、以下のコードサンプルを示します:
- カレンダーアイテムを作成して保存
- カレンダーアイテムを MSG ファイルとして保存
- MAPI カレンダーアイテムの製品 ID を ICS に保存
- イベントの総数を取得
- 表示リマインダーを追加
- 音声リマインダーを追加
- カレンダー ファイルから添付ファイルを追加/取得
- 会議出席依頼における受信者のステータスを確認
- 標準タイムゾーンから MAPI カレンダータイムゾーンを作成
- 予定のリマインダーを設定
- HTML 本文付きの Appointment EML を MSG に変換
- MAPI カレンダー アイテムの状態を手動で設定する
カレンダーアイテムの作成と保存
以下のコードスニペットは、ICS 形式でカレンダー アイテムを作成および保存する方法を示します。
// The path to the File directory.
string dataDir = RunExamples.GetDataDir_Outlook();
// Create the appointment
MapiCalendar calendar = new MapiCalendar(
"LAKE ARGYLE WA 6743",
"Appointment",
"This is a very important meeting :)",
new DateTime(2012, 10, 2, 13, 0, 0),
new DateTime(2012, 10, 2, 14, 0, 0));
calendar.Save(dataDir + "CalendarItem_out.ics", AppointmentSaveFormat.Ics);
カレンダーアイテムを MSG ファイルとして保存
以下のコードスニペットは、カレンダー アイテムを MSG として保存する方法を示します。
calendar.Save(dataDir + "CalendarItemAsMSG_out.Msg", AppointmentSaveFormat.Msg);
MAPI カレンダーアイテムの製品 ID を ICS に保存
この ProductIdentifier プロパティ( MapiCalendarIcsSaveOptions クラスは、元の日付と時刻情報およびカスタム製品識別子を保持したまま、MAPI カレンダー アイテムを iCalendar (ICS) ファイルに保存するために使用されます。プロパティは、iCalendar オブジェクトを作成した製品の識別子を指定します。
以下のコードサンプルは、MAPI カレンダー オブジェクト内で iCalendar (ICS) データを操作する方法を示します:
var icsSaveOptions = new MapiCalendarIcsSaveOptions
{
KeepOriginalDateTimeStamp = true,
ProductIdentifier = "Foo Ltd"
};
mapiCalendar.Save("my.ics", icsSaveOptions);
イベントの総数を取得
この CalendarReader クラスはカレンダー イベントを簡単に処理できるようにします。次のプロパティとメソッドで複数のイベントを操作できます:
- CalendarReader.Count - CalendarReader クラスの Count プロパティは、カレンダーに存在する Vevent コンポーネント(イベント)の数を取得でき、総イベント数の追跡が容易になります。
- CalendarReader.IsMultiEvents - このプロパティは、カレンダーが複数のイベントを含むかどうかを判定します。カレンダーに複数のイベントがあるかどうかを示すブール値を提供し、単一イベントか複数イベントかの識別に役立ちます。
- CalendarReader.Method - Method プロパティは、カレンダーオブジェクトに関連付けられた iCalendar のメソッドタイプを取得します。たとえば “REQUEST”、 “PUBLISH”、または “CANCEL” のようなメソッドタイプを返し、カレンダーの目的に関する有益な情報を提供します。
- CalendarReader.Version - iCalendar のバージョンを取得します。
- CalendarReader.LoadAsMultiple() このメソッドは、複数のイベントを含むカレンダーからイベントリストを読み込むことを可能にします。Appointment オブジェクトのリストを返し、各イベントに個別に簡単にアクセスおよび処理できます。
以下のコード例は、これらの機能をプロジェクトに実装する方法を示します。
var reader = new CalendarReader(fileName);
Console.WriteLine("Calendar contains " + reader.Count + " events");
Console.WriteLine("The Version of the calendar is " + reader.Version);
Console.WriteLine("The Method of the calendar is " + reader.Method);
Console.WriteLine("Does the calendar contain multiple events? - " + reader.IsMultiEvents);
List<Appointment> appointments = reader.LoadAsMultiple();
表示リマインダーを追加
以下のコードスニペットは、カレンダーに表示リマインダーを追加する方法を示します。
// The path to the File directory.
string dataDir = RunExamples.GetDataDir_Outlook();
// Create Appointment
Appointment app = new Appointment("Home", DateTime.Now.AddHours(1), DateTime.Now.AddHours(1), "organizer@domain.com", "attendee@gmail.com");
MailMessage msg = new MailMessage();
msg.AddAlternateView(app.RequestApointment());
MapiMessage mapi = MapiMessage.FromMailMessage(msg);
MapiCalendar calendar = (MapiCalendar)mapi.ToMapiMessageItem();
// Set calendar Properties
calendar.ReminderSet= true;
calendar.ReminderDelta = 45;//45 min before start of event
string savedFile = (dataDir + "calendarWithDisplayReminder.ics");
calendar.Save(savedFile, AppointmentSaveFormat.Ics);
音声リマインダーを追加
以下のコードスニペットは、カレンダーに音声リマインダーを追加する方法を示します。
// The path to the File directory.
string dataDir = RunExamples.GetDataDir_Outlook();
Appointment app = new Appointment("Home", DateTime.Now.AddHours(1), DateTime.Now.AddHours(1), "organizer@domain.com", "attendee@gmail.com");
MailMessage msg = new MailMessage();
msg.AddAlternateView(app.RequestApointment());
MapiMessage mapi = MapiMessage.FromMailMessage(msg);
MapiCalendar calendar = (MapiCalendar)mapi.ToMapiMessageItem();
// Set calendar properties
calendar.ReminderSet = true;
calendar.ReminderDelta = 58;//58 min before start of event
calendar.ReminderFileParameter = dataDir + "Alarm01.wav";
string savedFile = (dataDir + "calendarWithAudioReminder_out.ics");
calendar.Save(savedFile, AppointmentSaveFormat.Ics);
カレンダー ファイルから添付ファイルを追加/取得
以下のコードスニペットは、カレンダー ファイルから添付ファイルを追加/取得する方法を示します。
string[] files = new string[3];
files[0] = dataDir + "attachment_1.doc";
files[1] = dataDir + "download.png";
files[2] = dataDir + "Desert.jpg";
Appointment app1 = new Appointment("Home", DateTime.Now.AddHours(1), DateTime.Now.AddHours(1), "organizer@domain.com", "attendee@gmail.com");
foreach (string file in files)
{
using (MemoryStream ms = new MemoryStream(File.ReadAllBytes(file)))
{
app1.Attachments.Add(new Attachment(ms, Path.GetFileName(file)));
}
}
app1.Save(dataDir + "appWithAttachments_out.ics", AppointmentSaveFormat.Ics);
Appointment app2 = Appointment.Load(dataDir + "appWithAttachments_out.ics");
Console.WriteLine(app2.Attachments.Count);
foreach (Attachment att in app2.Attachments)
Console.WriteLine(att.Name);
会議出席依頼における受信者のステータスを確認
以下のコードスニペットは、会議出席依頼から受信者のステータスを表示する方法を示します。
MapiMessage message = MapiMessage.FromFile(fileName);
foreach (MapiRecipient recipient in message.Recipients)
{
Console.WriteLine(recipient.RecipientTrackStatus);
}
標準タイムゾーンから MAPI カレンダータイムゾーンを作成
以下のコードスニペットは、標準タイムゾーンから MapiCalendarTimeZone を作成する方法を示します。
MapiCalendarTimeZone timeZone = new MapiCalendarTimeZone(TimeZoneInfo.Local);
予定のリマインダーを設定
予定が作成されたときにリマインダーを追加できます。これらのアラームは、スケジュール開始 n 分前や、n 回の間隔で繰り返すなど、さまざまな条件でトリガーできます。BEGIN:VALARM と END:VALARM で囲まれたスクリプト内で、さまざまなタグを使用してこれらのトリガーを作成できます。予定にリマインダーを設定する方法には複数のバリエーションがあります。
リマインダー設定のためにタグを追加
以下のコードスニペットは、タグを追加してリマインダーを設定する方法を示します。
// The path to the File directory.
string dataDir = RunExamples.GetDataDir_Outlook();
string location = "Meeting Location: Room 5";
DateTime startDate = new DateTime(1997, 3, 18, 18, 30, 00),
endDate = new DateTime(1997, 3, 18, 19, 30, 00);
MailAddress organizer = new MailAddress("aaa@amail.com", "Organizer");
MailAddressCollection attendees = new MailAddressCollection();
attendees.Add(new MailAddress("bbb@bmail.com", "First attendee"));
Appointment target = new Appointment(location, startDate, endDate, organizer, attendees);
// Audio alarm that will sound at a precise time and
// Repeat 4 more times at 15 minute intervals:
AppointmentReminder audioReminder = new AppointmentReminder();
audioReminder.Trigger = new ReminderTrigger(new DateTime(1997, 3, 17, 13, 30, 0, DateTimeKind.Utc));
audioReminder.Repeat = 4;
audioReminder.Duration = new ReminderDuration(new TimeSpan(0, 15, 0));
audioReminder.Action = ReminderAction.Audio;
ReminderAttachment attach = new ReminderAttachment(new Uri("ftp://Host.com/pub/sounds/bell-01.aud"));
audioReminder.Attachments.Add(attach);
target.Reminders.Add(audioReminder);
// Display alarm that will trigger 30 minutes before the
// Scheduled start of the event it is
// Associated with and will repeat 2 more times at 15 minute intervals:
AppointmentReminder displayReminder = new AppointmentReminder();
ReminderDuration dur = new ReminderDuration(new TimeSpan(0, -30, 0));
displayReminder.Trigger = new ReminderTrigger(dur, ReminderRelated.Start);
displayReminder.Repeat = 2;
displayReminder.Duration = new ReminderDuration(new TimeSpan(0, 15, 0));
displayReminder.Action = ReminderAction.Display;
displayReminder.Description = "Breakfast meeting with executive team at 8:30 AM EST";
target.Reminders.Add(displayReminder);
// Email alarm that will trigger 2 days before the
// Scheduled due date/time. It does not
// Repeat. The email has a subject, body and attachment link.
AppointmentReminder emailReminder = new AppointmentReminder();
ReminderDuration dur1 = new ReminderDuration(new TimeSpan(-2, 0, 0, 0));
emailReminder.Trigger = new ReminderTrigger(dur1, ReminderRelated.Start);
ReminderAttendee attendee = new ReminderAttendee("john_doe@host.com");
emailReminder.Attendees.Add(attendee);
emailReminder.Action = ReminderAction.Email;
emailReminder.Summary = "REMINDER: SEND AGENDA FOR WEEKLY STAFF MEETING";
emailReminder.Description = @"A draft agenda needs to be sent out to the attendees to the weekly managers meeting (MGR-LIST). Attached is a pointer the document template for the agenda file.";
ReminderAttachment attach1 = new ReminderAttachment(new Uri("http://Host.com/templates/agenda.doc"));
emailReminder.Attachments.Add(attach1);
target.Reminders.Add(emailReminder);
// Procedural alarm that will trigger at a precise date/time
// And will repeat 23 more times at one hour intervals. The alarm will
// Invoke a procedure file.
AppointmentReminder procReminder = new AppointmentReminder();
procReminder.Trigger = new ReminderTrigger(new DateTime(1998, 1, 1, 5, 0, 0, DateTimeKind.Utc));
procReminder.Repeat = 23;
procReminder.Duration = new ReminderDuration(new TimeSpan(1, 0, 0));
procReminder.Action = ReminderAction.Procedure;
ReminderAttachment attach2 = new ReminderAttachment(new Uri("ftp://Host.com/novo-procs/felizano.exe"));
procReminder.Attachments.Add(attach2);
target.Reminders.Add(procReminder);
target.Save(dataDir + "savedFile_out.ics");
HTML 本文付きの Appointment EML を MSG に変換
バージョン 19.3 以降、Aspose.Email は、予定の HTML 本文を保持したまま Appointment EML を MSG に変換する機能を提供します。Aspose.Email は MapiConversionOptions.ForcedRtfBodyForAppointment プロパティはデフォルトで true です。値が MapiConversionOptions.ForcedRtfBodyForAppointment が true に設定されていると、予定の本文は RTF フォーマットに変換されます。HTML フォーマットで予定の本文形式を保持するには、次の値を設定します MapiConversionOptions.ForcedRtfBodyForAppointment を false に。
以下の例は次の使用法を示しています MapiConversionOptions.ForcedRtfBodyForAppointment HTML フォーマットで予定の本文形式を保持するプロパティです。
// Outlook directory
string dataDir = RunExamples.GetDataDir_Outlook();
MailMessage mailMessage = MailMessage.Load(dataDir + "TestAppointment.eml");
MapiConversionOptions conversionOptions = new MapiConversionOptions();
conversionOptions.Format = OutlookMessageFormat.Unicode;
// default value for ForcedRtfBodyForAppointment is true
conversionOptions.ForcedRtfBodyForAppointment = false;
MapiMessage mapiMessage = MapiMessage.FromMailMessage(mailMessage, conversionOptions);
Console.WriteLine("Body Type: " + mapiMessage.BodyType);
mapiMessage.Save(dataDir + "TestAppointment_out.msg");
MAPI カレンダーアイテムの状態を手動で設定
MAPI カレンダーオブジェクトの状態を明示的に設定し、デフォルトの動作を上書きします。これにより、特に受信した会議リクエストを処理する際のカレンダーイベントの状態をより細かく制御できます。デフォルトでは、会議が作成されると、その状態は MapiCalendarState.Meeting。 受信者の受信トレイに届くと、自動的に次の状態に変わります MapiCalendarState.Received、メッセージクラスが “IPM.Schedule.Meeting.Request” に更新されます。使用すると SetStateForced 状態を手動で Received に設定でき、カレンダーを MSG ファイルとして保存する際にオーガナイザ情報を保持するのに役立ちます。ただし、これにより会議の適切な転送や再送信ができなくなる可能性があります。
以下のコードサンプルは、作成方法を示します。 MapiCalendar オブジェクトにオーガナイザを割り当て、状態を両方に明示的に設定します Meeting および Received 使用して SetStateForcedそれからカレンダーアイテムを .msg ファイルとして保存します。
MapiCalendar appointment = new MapiCalendar(
"LAKE ARGYLE WA 6743",
"Appointment",
"This is a very important meeting :)",
new DateTime(2024, 5, 10, 12, 30, 0, DateTimeKind.Utc),
new DateTime(2024, 5, 10, 13, 30, 0, DateTimeKind.Utc));
appointment.Organizer = new MapiElectronicAddress
{
EmailAddress = "test@aaa.com",
DisplayName = "test display Name"
};
appointment.SetStateForced(MapiCalendarState.Meeting | MapiCalendarState.Received);
appointment.Save("appointment.msg", AppointmentSaveFormat.Msg);
関連項目
- 予定の管理 — iCalendar (ICS) の予定と会議リクエストを操作します。
- PST ファイル内のカレンダー アイテムの管理 — PST 内のカレンダー アイテムを保存および読み取ります。