Outlook カレンダー アイテムの操作
MapiCalendar の操作
Aspose.Email の MapiCalendar クラスは、カレンダー アイテムのさまざまなプロパティを設定するためのメソッドと属性を提供します。本記事では、次のコードサンプルを示します:
カレンダー アイテムの作成と保存
以下のコードスニペットは、ICS 形式でカレンダー アイテムを作成および保存する方法を示します。
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
// The path to the File directory.
String dataDir = "outlook/";
Calendar cal = Calendar.getInstance();
cal.set(2012, Calendar.OCTOBER, 2, 13, 0, 0);
Date startDate = cal.getTime();
cal.set(2012, Calendar.OCTOBER, 2, 14, 0, 0);
Date endDate = cal.getTime();
MapiCalendar calendar = new MapiCalendar("LAKE ARGYLE WA 6743",
"Appointment",
"This is a very important meeting :)",
startDate,
endDate);
calendar.save(dataDir + "CalendarItem_out.ics", AppointmentSaveFormat.Ics);
カレンダー アイテムを MSG として保存
以下のコードスニペットは、カレンダー アイテムを MSG として保存する方法を示します。
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
calendar.save(dataDir + "CalendarItemAsMSG_out.Msg", AppointmentSaveFormat.Msg);
カレンダー アイテムを ICS に保存するときに製品 ID を設定
この ProductIdentifier プロパティ( MapiCalendarIcsSaveOptions クラスは、元の日付と時刻情報およびカスタム製品識別子を保持したまま、MAPI カレンダー アイテムを iCalendar (ICS) ファイルに保存するために使用されます。プロパティは、iCalendar オブジェクトを作成した製品の識別子を指定します。
以下のコードサンプルは、MAPI カレンダー オブジェクト内で iCalendar (ICS) データを操作する方法を示します:
MapiCalendarIcsSaveOptions icsSaveOptions = new MapiCalendarIcsSaveOptions();
icsSaveOptions.setKeepOriginalDateTimeStamp(true);
icsSaveOptions.setProductIdentifier("Foo Ltd");
mapiCalendar.save("my.ics", icsSaveOptions);
カレンダーに表示リマインダーを追加
以下のコードスニペットは、カレンダーに表示リマインダーを追加する方法を示します。
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
// The path to the File directory.
String dataDir = "outlook/";
Calendar jCalendar = Calendar.getInstance();
jCalendar.add(Calendar.HOUR, 1);
Date startDate = jCalendar.getTime();
Date endDate = jCalendar.getTime();
MailAddressCollection attendees = new MailAddressCollection();
attendees.addItem(new MailAddress("attendee@domain.com", "Attendee"));
// Create Appointment
Appointment app = new Appointment("Home",
startDate,
endDate,
new MailAddress("organizer@domain.com", "Organizer"),
attendees);
MailMessage msg = new MailMessage();
msg.addAlternateView(app.requestApointment());
MapiMessage mapi = MapiMessage.fromMailMessage(msg);
MapiCalendar calendar = (MapiCalendar) mapi.toMapiMessageItem();
// Set calendar Properties
calendar.setReminderSet(true);
calendar.setReminderDelta(5); // 45 min before start of event
String savedFile = (dataDir + "calendarWithDisplayReminder.ics");
calendar.save(savedFile, AppointmentSaveFormat.Ics);
カレンダーに音声リマインダーを追加
以下のコードスニペットは、カレンダーに音声リマインダーを追加する方法を示します。
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
// The path to the File directory.
String dataDir = "outlook/";
Calendar jCalendar = Calendar.getInstance();
jCalendar.add(Calendar.HOUR, 1);
Date startDate = jCalendar.getTime();
Date endDate = jCalendar.getTime();
MailAddressCollection attendees = new MailAddressCollection();
attendees.addItem(new MailAddress("attendee@domain.com", "Attendee"));
Appointment app = new Appointment("Home",
startDate,
endDate,
new MailAddress("organizer@domain.com", "Organizer"),
attendees);
MailMessage msg = new MailMessage();
msg.addAlternateView(app.requestApointment());
MapiMessage mapi = MapiMessage.fromMailMessage(msg);
MapiCalendar cal = (MapiCalendar) mapi.toMapiMessageItem();
cal.setReminderSet(true);
cal.setReminderDelta(58); // 58 min before start of event
cal.setReminderFileParameter(dataDir + "Alarm01.wav");
String savedFile = dataDir + "calendarWithAudioReminder_out.ics";
cal.save(savedFile, AppointmentSaveFormat.Ics);
カレンダー ファイルから添付ファイルを追加/取得
以下のコードスニペットは、カレンダー ファイルから添付ファイルを追加/取得する方法を示します。
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
// The path to the File directory.
String dataDir = "outlook/";
Calendar jCalendar = Calendar.getInstance();
jCalendar.add(Calendar.HOUR, 1);
Date startDate = jCalendar.getTime();
Date endDate = jCalendar.getTime();
String[] files = new String[3];
files[0] = "attachment_1.doc";
files[1] = "download.png";
files[2] = "Desert.jpg";
MailAddressCollection attendees = new MailAddressCollection();
attendees.addItem(new MailAddress("attendee@domain.com", "Attendee"));
Appointment app1 = new Appointment("Home",
startDate,
endDate,
new MailAddress("organizer@domain.com", "Organizer"),
attendees);
for (String file : files) {
app1.getAttachments().addItem(new Attachment(dataDir + file));
}
app1.save(dataDir + "appWithAttachments_out.ics", AppointmentSaveFormat.Ics);
Appointment app2 = Appointment.load(dataDir + "appWithAttachments_out.ics");
System.out.println(app2.getAttachments().size());
for (Attachment att : app2.getAttachments())
System.out.println(att.getName());
会議リクエストからの受信者ステータス
以下のコードスニペットは、会議リクエストから受信者のステータスを取得する方法を示します。
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
String fileName = "outlook/test.msg";
MapiMessage message = MapiMessage.fromFile(fileName);
for (MapiRecipient recipient : message.getRecipients()) {
System.out.println(recipient.getRecipientTrackStatus());
}
カレンダー予定の状態を明示的に設定
Aspose.Email は、 MapiCalendar オブジェクトを明示的に設定し、デフォルトの動作を上書きします。 setStateForced メソッドは、特に受信した会議リクエストを処理する際に、カレンダーイベントの状態をより細かく制御できます。デフォルトでは、会議が作成されると、その状態は MapiCalendarState.Meeting。 受信者の受信トレイに届くと、自動的に次の状態に変わります MapiCalendarState.Received、メッセージ クラスが次のように更新されます IPM.Schedule.Meeting.Request。 使用 SetStateForced 状態を手動で Received に設定でき、カレンダーを MSG ファイルとして保存する際に主催者情報を保持するのに有用です。ただし、これにより会議の正しい転送や再送信ができなくなる可能性があります。
以下のコードサンプルは、この機能の実装に役立ちます:
Calendar c = Calendar.getInstance();
c.set(2024, Calendar.MAY, 10, 12, 30, 0);
Date startDate = c.getTime();
c.set(2024, Calendar.MAY, 10, 13, 30, 0);
Date endDate = c.getTime();
MapiCalendar appointment = new MapiCalendar(
"LAKE ARGYLE WA 6743",
"Appointment",
"This is a very important meeting :)",
startDate,
endDate);
MapiElectronicAddress organizer = new MapiElectronicAddress();
organizer.setEmailAddress("test@aaa.com");
organizer.setDisplayName("test display Name");
appointment.setOrganizer(organizer);
appointment.setStateForced(MapiCalendarState.Meeting | MapiCalendarState.Received);
appointment.save("appointment.msg", AppointmentSaveFormat.Msg);
標準タイムゾーンから MapiCalendarTimeZone を作成
以下のコードスニペットは、作成方法を示します MapiCalendarTimeZone 標準タイムゾーンから。
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
MapiCalendarTimeZone timeZone = new MapiCalendarTimeZone("Eastern Standard Time");
作成した予定でリマインダーを設定
予定が作成されたときにリマインダーを追加できます。これらのアラームは、スケジュール開始 n 分前や、n 回の間隔で繰り返すなど、さまざまな条件でトリガーできます。BEGIN:VALARM と END:VALARM で囲まれたスクリプト内で、さまざまなタグを使用してこれらのトリガーを作成できます。予定にリマインダーを設定する方法には複数のバリエーションがあります。
タグを追加してリマインダーを設定
以下のコードスニペットは、タグを追加してリマインダーを設定する方法を示します。
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
// The path to the File directory.
String dataDir = RunExamples.getDataDir_Outlook();
long MIN_MS = 60 * 1000;
long HR_MS = 60 * MIN_MS;
long DAY_MS = 24 * HR_MS;
String location = "Meeting Location: Room 5";
Date startDate = getDate(1997, 3, 18, 18, 30, 00);
Date endDate = getDate(1997, 3, 18, 19, 30, 00);
MailAddress organizer = new MailAddress("aaa@amail.com", "Organizer");
MailAddressCollection attendees = new MailAddressCollection();
attendees.addItem(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.setTrigger(new ReminderTrigger(getDate(1997, 3, 17, 13, 30, 0)));
audioReminder.setRepeat(4);
audioReminder.setDuration(new ReminderDuration(15 * MIN_MS));
audioReminder.setAction(ReminderAction.Audio);
ReminderAttachment attach = new ReminderAttachment(new URI("ftp://Host.com/pub/sounds/bell-01.aud"));
audioReminder.getAttachments().addItem(attach);
target.getReminders().addItem(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(-30 * MIN_MS);
displayReminder.setTrigger(new ReminderTrigger(dur, ReminderRelated.Start));
displayReminder.setRepeat(2);
displayReminder.setDuration(new ReminderDuration(15 * MIN_MS));
displayReminder.setAction(ReminderAction.Display);
displayReminder.setDescription("Breakfast meeting with executive team at 8:30 AM EST");
target.getReminders().addItem(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(-2 * DAY_MS);
emailReminder.setTrigger(new ReminderTrigger(dur1, ReminderRelated.Start));
ReminderAttendee attendee = new ReminderAttendee("john_doe@host.com");
emailReminder.getAttendees().addItem(attendee);
emailReminder.setAction(ReminderAction.Email);
emailReminder.setSummary("REMINDER: SEND AGENDA FOR WEEKLY STAFF MEETING");
emailReminder.setDescription("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.getAttachments().addItem(attach1);
target.getReminders().addItem(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.setTrigger(new ReminderTrigger(getDate(1998, 1, 1, 5, 0, 0)));
procReminder.setRepeat(23);
procReminder.setDuration(new ReminderDuration(1 * DAY_MS));
procReminder.setAction(ReminderAction.Procedure);
ReminderAttachment attach2 = new ReminderAttachment(new URI("ftp://Host.com/novo-procs/felizano.exe"));
procReminder.getAttachments().addItem(attach2);
target.getReminders().addItem(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 フォーマットで予定の本文形式を保持するプロパティです。
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
// The path to the File directory.
String dataDir = "outlook/";
MailMessage mailMessage = MailMessage.load(dataDir + "TestAppointment.eml");
MapiConversionOptions conversionOptions = new MapiConversionOptions();
conversionOptions.setFormat(OutlookMessageFormat.Unicode);
// default value for ForcedRtfBodyForAppointment is true
conversionOptions.setForcedRtfBodyForAppointment(false);
MapiMessage mapiMessage = MapiMessage.fromMailMessage(mailMessage, conversionOptions);
if (mapiMessage.getBodyType() == BodyContentType.Html) {
System.out.println("Body Type: Html");
} else if (mapiMessage.getBodyType() == BodyContentType.Rtf) {
System.out.println("Body Type: Rtf");
}
mapiMessage.save(dataDir + "TestAppointment_out.msg");