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번 반복, 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 본문을 포함한 약속 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");