Outlook 캘린더 항목 작업

Outlook은 약속 및 회의를 캘린더 항목으로 저장합니다. Aspose.Email for C++는 이러한 항목을 MapiCalendar 클래스에서 다룹니다: 처음부터 만들 수 있고, 알림 및 시간대를 지정한 뒤 Outlook의 MSG 형식이나 iCalendar(ICS) 파일로 저장할 수 있습니다. 여러 독립 알람이나 임베디드 파일과 같은 ICS 형식의 일부 기능은 표준 기반 Appointment 클래스 대신; 두 가지가 아래에 나타납니다. PST 파일 내부에 보관된 캘린더 항목은 PST 파일에서 캘린더 항목 작업.

이 문서의 샘플은 다음 헤더와 네임스페이스를 사용합니다:

#include <MailMessage.h>
#include <MailAddress.h>
#include <MailAddressCollection.h>
#include <Attachment.h>
#include <AttachmentCollection.h>
#include <Calendar/Appointment.h>
#include <Calendar/AppointmentSaveFormat.h>
#include <Calendar/AppointmentReminder.h>
#include <Calendar/AppointmentReminderCollection.h>
#include <Calendar/CalendarReader.h>
#include <Calendar/ReminderAction.h>
#include <Calendar/ReminderAttachment.h>
#include <Calendar/ReminderAttachmentCollection.h>
#include <Calendar/ReminderAttendee.h>
#include <Calendar/ReminderAttendeeCollection.h>
#include <Calendar/ReminderDuration.h>
#include <Calendar/ReminderRelated.h>
#include <Calendar/ReminderTrigger.h>
#include <Mapi/MapiCalendar.h>
#include <Mapi/MapiCalendarIcsSaveOptions.h>
#include <Mapi/MapiCalendarState.h>
#include <Mapi/MapiCalendarTimeZone.h>
#include <Mapi/MapiElectronicAddress.h>
#include <Mapi/MapiMessage.h>
#include <Mapi/MapiConversionOptions.h>
#include <Mapi/MapiRecipient.h>
#include <Mapi/MapiRecipientCollection.h>
#include <Mapi/MapiRecipientTrackStatus.h>
#include <Mapi/OutlookMessageFormat.h>
#include <Mapi/BodyContentType.h>
#include <system/collections/list_ext.h>
#include <system/convert.h>
#include <system/object_ext.h>
#include <system/timezone_info.h>
#include <system/timespan.h>
#include <system/uri.h>
#include <system/io/file.h>
#include <system/io/memory_stream.h>
#include <system/io/path.h>

using namespace System;
using namespace Aspose::Email;
using namespace Aspose::Email::Mapi;
using namespace Aspose::Email::Calendar;

캘린더 항목 만들기 및 저장

가장 간단한 생성자는 MapiCalendar 위치, 제목, 본문 및 이벤트의 시작과 끝을 가져옵니다. 저장 선택된 형식으로 항목을 씁니다 AppointmentSaveFormat: Ics 대부분의 캘린더 프로그램이 가져올 수 있는 iCalendar 파일을 생성합니다, Msg Outlook 항목입니다.

// location, subject, body, start and end
SharedPtr<MapiCalendar> calendar = MakeObject<MapiCalendar>(u"LAKE ARGYLE WA 6743", u"Appointment",
    u"This is a very important meeting", DateTime(2025, 10, 2, 13, 0, 0), DateTime(2025, 10, 2, 14, 0, 0));

// iCalendar, readable by almost any calendar program
calendar->Save(u"CalendarItem.ics", AppointmentSaveFormat::Ics);

// Outlook's own format
calendar->Save(u"CalendarItem.msg", AppointmentSaveFormat::Msg);

Console::WriteLine(u"Saved: " + calendar->get_Subject());

알림 추가

디스플레이 알림

Outlook 항목에는 단일 알림이 있습니다. ReminderSet 켜고 ReminderDelta 시작 전 몇 분 전에 작동하도록 설정합니다. ICS 파일에서 알림은 VALARM 블록; 샘플은 주요 라인을 출력합니다 - TRIGGER:-PT45M 및 ACTION:DISPLAY.

SharedPtr<MapiCalendar> calendar = MakeObject<MapiCalendar>(u"Home", u"Dentist",
    u"Bring the insurance card", DateTime(2025, 10, 2, 9, 0, 0), DateTime(2025, 10, 2, 10, 0, 0));

calendar->set_ReminderSet(true);
calendar->set_ReminderDelta(45);   // minutes before the start of the event

calendar->Save(u"CalendarWithDisplayReminder.ics", AppointmentSaveFormat::Ics);

for (String line : IO::File::ReadAllLines(u"CalendarWithDisplayReminder.ics"))
{
    if (line.StartsWith(u"BEGIN:VALARM") || line.StartsWith(u"TRIGGER") || line.StartsWith(u"ACTION"))
    {
        Console::WriteLine(line);
    }
}

오디오 알림

ReminderFileParameter 기본 사운드 대신 재생할 사운드 파일을 지정합니다. 그러면 알림이 오디오 알람으로 기록됩니다: ACTION:AUDIO 와 함께 ATTACH 파일을 가리키는 라인.

SharedPtr<MapiCalendar> calendar = MakeObject<MapiCalendar>(u"Home", u"Dentist",
    u"Bring the insurance card", DateTime(2025, 10, 2, 9, 0, 0), DateTime(2025, 10, 2, 10, 0, 0));

calendar->set_ReminderSet(true);
calendar->set_ReminderDelta(58);                         // minutes before the start of the event
calendar->set_ReminderFileParameter(u"Alarm01.wav");     // the sound to play instead of the default one

calendar->Save(u"CalendarWithAudioReminder.ics", AppointmentSaveFormat::Ics);

for (String line : IO::File::ReadAllLines(u"CalendarWithAudioReminder.ics"))
{
    if (line.StartsWith(u"TRIGGER") || line.StartsWith(u"ACTION") || line.StartsWith(u"ATTACH"))
    {
        Console::WriteLine(line);
    }
}

하나의 iCalendar 이벤트에 여러 알림

iCalendar 형식은 이벤트당 여러 개의 알람을 허용하며, 각각 고유한 트리거와 동작을 가집니다. Appointment 그것을 통해 노출합니다 알림 컬렉션 AppointmentReminder 객체:

  • ReminderTrigger - 고정된 순간이거나 ReminderDuration 이벤트의 시작 또는 끝을 기준으로;
  • Repeat 및 Duration - 알람이 추가로 발생하는 횟수 및 간격;
  • ReminderAction - Audio, Display, Email 또는 Procedure, 사운드 파일, 텍스트, 이메일 또는 프로그램을 페이로드로 사용합니다.

샘플은 각 종류별 알람을 하나씩 추가합니다; 저장된 파일에는 네 개가 포함됩니다 VALARM 블록.

SharedPtr<MailAddressCollection> attendees = MakeObject<MailAddressCollection>();
attendees->Add(MakeObject<MailAddress>(u"bbb@bmail.com", String(u"First attendee")));

SharedPtr<Appointment> appointment = MakeObject<Appointment>(u"Meeting Location: Room 5",
    DateTime(1997, 3, 18, 18, 30, 0), DateTime(1997, 3, 18, 19, 30, 0),
    MakeObject<MailAddress>(u"aaa@amail.com", String(u"Organizer")), attendees);

// a sound at a fixed moment, repeated 4 more times every 15 minutes
SharedPtr<AppointmentReminder> audio = MakeObject<AppointmentReminder>();
audio->set_Trigger(MakeObject<ReminderTrigger>(DateTime(1997, 3, 17, 13, 30, 0, DateTimeKind::Utc)));
audio->set_Repeat(4);
audio->set_Duration(MakeObject<ReminderDuration>(TimeSpan(0, 15, 0)));
audio->set_Action(ReminderAction::Audio);
audio->get_Attachments()->Add(MakeObject<ReminderAttachment>(MakeObject<Uri>(u"ftp://Host.com/pub/sounds/bell-01.aud")));
appointment->get_Reminders()->Add(audio);

// a message 30 minutes before the start, repeated 2 more times every 15 minutes
SharedPtr<AppointmentReminder> display = MakeObject<AppointmentReminder>();
display->set_Trigger(MakeObject<ReminderTrigger>(MakeObject<ReminderDuration>(TimeSpan(0, -30, 0)), ReminderRelated::Start));
display->set_Repeat(2);
display->set_Duration(MakeObject<ReminderDuration>(TimeSpan(0, 15, 0)));
display->set_Action(ReminderAction::Display);
display->set_Description(u"Breakfast meeting with executive team at 8:30 AM EST");
appointment->get_Reminders()->Add(display);

// an email two days before the start, with a subject, a body and a link to a document
SharedPtr<AppointmentReminder> email = MakeObject<AppointmentReminder>();
email->set_Trigger(MakeObject<ReminderTrigger>(MakeObject<ReminderDuration>(TimeSpan(-2, 0, 0, 0)), ReminderRelated::Start));
email->get_Attendees()->Add(MakeObject<ReminderAttendee>(u"john_doe@host.com"));
email->set_Action(ReminderAction::Email);
email->set_Summary(u"REMINDER: SEND AGENDA FOR WEEKLY STAFF MEETING");
email->set_Description(u"A draft agenda needs to be sent out to the attendees of the weekly managers meeting.");
email->get_Attachments()->Add(MakeObject<ReminderAttachment>(MakeObject<Uri>(u"http://Host.com/templates/agenda.doc")));
appointment->get_Reminders()->Add(email);

// a program started at a fixed moment, repeated 23 more times every hour
SharedPtr<AppointmentReminder> procedure = MakeObject<AppointmentReminder>();
procedure->set_Trigger(MakeObject<ReminderTrigger>(DateTime(1998, 1, 1, 5, 0, 0, DateTimeKind::Utc)));
procedure->set_Repeat(23);
procedure->set_Duration(MakeObject<ReminderDuration>(TimeSpan(1, 0, 0)));
procedure->set_Action(ReminderAction::Procedure);
procedure->get_Attachments()->Add(MakeObject<ReminderAttachment>(MakeObject<Uri>(u"ftp://Host.com/novo-procs/felizano.exe")));
appointment->get_Reminders()->Add(procedure);

appointment->Save(u"AppointmentWithReminders.ics", AppointmentSaveFormat::Ics);

int32_t alarms = 0;
for (String line : IO::File::ReadAllLines(u"AppointmentWithReminders.ics"))
{
    if (line == u"BEGIN:VALARM")
    {
        alarms++;
    }
    if (line.StartsWith(u"ACTION"))
    {
        Console::WriteLine(line);
    }
}
Console::WriteLine(u"VALARM blocks: " + Convert::ToString(alarms));

이벤트의 시간대 설정

MapiCalendarTimeZone 다음으로부터 직접 빌드할 수 있습니다 TimeZoneInfo 객체 - 여기서는 프로그램이 실행되는 컴퓨터의 시간대입니다. 다음에 할당됩니다 StartDateTimeZone 및 EndDateTimeZone, 이렇게 하면 ICS 출력이 해당 시간대의 시간을 표시합니다, 예를 들어 DTSTART;TZID=Europe/Moscow:20251002T160000.

// a MAPI time zone built from the time zone of this computer
SharedPtr<MapiCalendarTimeZone> timeZone = MakeObject<MapiCalendarTimeZone>(TimeZoneInfo::get_Local());

SharedPtr<MapiCalendar> calendar = MakeObject<MapiCalendar>(u"Office", u"Planning",
    u"Quarter planning", DateTime(2025, 10, 2, 13, 0, 0), DateTime(2025, 10, 2, 14, 0, 0));
calendar->set_StartDateTimeZone(timeZone);
calendar->set_EndDateTimeZone(timeZone);

calendar->Save(u"CalendarWithTimeZone.ics", AppointmentSaveFormat::Ics);

for (String line : IO::File::ReadAllLines(u"CalendarWithTimeZone.ics"))
{
    if (line.StartsWith(u"TZID") || line.StartsWith(u"DTSTART") || line.StartsWith(u"BEGIN:VTIMEZONE"))
    {
        Console::WriteLine(line);
    }
}

첨부 파일 추가 및 읽기

에 첨부된 파일 Appointment 그것의 첨부 파일 컬렉션은 ICS 파일에 포함되어 파일과 함께 이동하며, 파일이 다음으로 열릴 때 복원됩니다 Appointment::Load.

SharedPtr<MailAddressCollection> attendees = MakeObject<MailAddressCollection>();
attendees->Add(MakeObject<MailAddress>(u"attendee@domain.com"));

SharedPtr<Appointment> appointment = MakeObject<Appointment>(u"Home",
    DateTime(2025, 10, 2, 9, 0, 0), DateTime(2025, 10, 2, 10, 0, 0),
    MakeObject<MailAddress>(u"organizer@domain.com"), attendees);

// attach files from disk
for (String file : { String(u"1.jpg"), String(u"portrait.jpg") })
{
    appointment->get_Attachments()->Add(MakeObject<Attachment>(
        MakeObject<IO::MemoryStream>(IO::File::ReadAllBytes(file)), IO::Path::GetFileName(file)));
}
appointment->Save(u"AppointmentWithAttachments.ics", AppointmentSaveFormat::Ics);

// the attachments are embedded in the ICS file and come back when it is loaded
SharedPtr<Appointment> loaded = Appointment::Load(u"AppointmentWithAttachments.ics");
Console::WriteLine(u"Attachments: " + Convert::ToString(loaded->get_Attachments()->get_Count()));

for (SharedPtr<Attachment> attachment : loaded->get_Attachments())
{
    Console::WriteLine(u"   " + attachment->get_Name());
}

회의 참석자의 응답 상태 확인

모든 회의 요청 수신자는 해당 사람이 어떻게 응답했는지 기록합니다. MapiRecipient::get_RecipientTrackStatus 다음 형태로 반환합니다 MapiRecipientTrackStatus 값 - None 아직 답변이 없을 때까지 기다린 후, 그때 Tentative, Accepted 또는 Declined.

SharedPtr<MapiMessage> message = MapiMessage::Load(u"Test_Meeting.msg");

for (SharedPtr<MapiRecipient> recipient : message->get_Recipients())
{
    // None, Tentative, Accepted or Declined
    Console::WriteLine(recipient->get_DisplayName() + u": " + ObjectExt::ToString(recipient->get_RecipientTrackStatus()));
}

캘린더 항목의 ICS 출력 제어

MapiCalendarIcsSaveOptions ICS 형식 옵션 객체입니다. KeepOriginalDateTimeStamp 작성합니다 DTSTAMP 현재 시간이 아닌 원본 항목의 시간으로, 그리고 ProductIdentifier 설정합니다 PRODID 파일을 만든 프로그램 이름이 적힌 줄.

SharedPtr<MapiCalendar> calendar = MakeObject<MapiCalendar>(u"LAKE ARGYLE WA 6743", u"Appointment",
    u"This is a very important meeting", DateTime(2025, 10, 2, 13, 0, 0), DateTime(2025, 10, 2, 14, 0, 0));

SharedPtr<MapiCalendarIcsSaveOptions> icsSaveOptions = MakeObject<MapiCalendarIcsSaveOptions>();
icsSaveOptions->set_KeepOriginalDateTimeStamp(true);   // do not refresh DTSTAMP
icsSaveOptions->set_ProductIdentifier(u"Foo Ltd");     // the PRODID of the output file

calendar->Save(u"CalendarWithProductId.ics", icsSaveOptions);

Console::WriteLine(IO::File::ReadAllText(u"CalendarWithProductId.ics").Substring(0, 120));

읽기 전 캘린더 파일 검사

CalendarReader 단일 이벤트를 읽기 전에 파일이 열렸던 파일을 설명합니다: Count 수는 VEVENT 구성 요소, IsMultiEvents 여러 개가 있는지 여부를 나타냅니다, Version iCalendar 버전과 Method 그 METHOD 속성 - PUBLISH, REQUEST, CANCEL 등등. LoadAsMultiple 전체 이벤트를 한 번에 반환합니다. 개별적으로 진행하지 않습니다.

SharedPtr<CalendarReader> reader = MakeObject<CalendarReader>(u"US-Holidays.ics");

Console::WriteLine(u"Events in the calendar: " + Convert::ToString(reader->get_Count()));
Console::WriteLine(u"iCalendar version: " + reader->get_Version());
Console::WriteLine(u"Method: " + Convert::ToString(static_cast<int32_t>(reader->get_Method())));
Console::WriteLine(u"More than one event: " + Convert::ToString(reader->get_IsMultiEvents()));

// all the events at once instead of one by one
auto appointments = reader->LoadAsMultiple();
Console::WriteLine(u"Loaded: " + Convert::ToString(appointments->get_Count()));

HTML 본문 유지 및 상태 명시적 설정

약속이 Outlook 항목으로 변환될 때 중요한 두 가지 세부 사항이 있습니다.

기본적으로 본문은 RTF로 변환됩니다. 이는 Outlook이 일정 항목을 저장하는 방식이기 때문입니다. 다음을 설정하면 ForcedRtfBodyForAppointment to false HTML 본문을 유지합니다.

상태는 일반적으로 일정 항목의 수명 주기를 따릅니다: 방금 생성된 항목은 Meeting, 그리고 다음과 같이 됩니다 Received 수신자의 사서함에 도착할 때. SetStateForced 값을 직접 할당합니다. 이는 수신된 회의가 MSG로 저장될 때 주최자 정보를 유지하는 방법입니다. 이후 항목은 전달 또는 재전송에 적합하지 않을 수 있습니다.

// keep the HTML body of an appointment instead of converting it to RTF
SharedPtr<MailMessage> mailMessage = MailMessage::Load(u"Test_Meeting.msg");

SharedPtr<MapiConversionOptions> conversionOptions = MakeObject<MapiConversionOptions>();
conversionOptions->set_Format(OutlookMessageFormat::Unicode);
conversionOptions->set_ForcedRtfBodyForAppointment(false); // the default is true

SharedPtr<MapiMessage> mapiMessage = MapiMessage::FromMailMessage(mailMessage, conversionOptions);
Console::WriteLine(u"Body type: " + ObjectExt::ToString(mapiMessage->get_BodyType()));

// set the state of a calendar item explicitly
SharedPtr<MapiCalendar> appointment = MakeObject<MapiCalendar>(u"LAKE ARGYLE WA 6743", u"Appointment",
    u"This is a very important meeting",
    DateTime(2025, 5, 10, 12, 30, 0, DateTimeKind::Utc),
    DateTime(2025, 5, 10, 13, 30, 0, DateTimeKind::Utc));

SharedPtr<MapiElectronicAddress> organizer = MakeObject<MapiElectronicAddress>();
organizer->set_EmailAddress(u"test@aaa.com");
organizer->set_DisplayName(u"test display Name");
appointment->set_Organizer(organizer);

// Meeting is the state of a new item; Received is what an item gets in the recipient's inbox
appointment->SetStateForced(MapiCalendarState::Meeting | MapiCalendarState::Received);

appointment->Save(u"ForcedState.msg", AppointmentSaveFormat::Msg);

캘린더 항목의 제품 식별자 읽기 및 설정

iCalendar 파일은 만든 제품을 다음에 기록합니다 PRODID 필드. Aspose.Email은 캘린더 항목을 ICS와 MSG 사이에 변환할 때 이 식별자를 유지하므로 항목의 출처를 추적할 수 있습니다. 다음 멤버를 통해 식별자에 접근합니다:

  • Appointment::get_ProductId() 및 Appointment::set_ProductId() - 해당 항목을 만든 제품의 식별자를 가져오거나 설정합니다 Appointment.
  • MapiCalendar::get_ProductId() 및 MapiCalendar::set_ProductId() - 해당 항목을 만든 제품의 식별자를 가져오거나 설정합니다 MapiCalendar.
  • MapiCalendarSaveOptions::set_ProductIdentifier() - 캘린더 항목을 저장할 때 기록되는 식별자를 설정합니다 MapiCalendarMsgSaveOptions 또는 MapiCalendarIcsSaveOptions.

다음 코드 샘플은 ICS 파일에서 제품 식별자를 읽고, 약속을 MSG로 변환하면서 AppointmentMsgSaveOptions, 새로운 식별자로 캘린더 항목을 저장하고, 그 다음 또 다른 식별자를 ICS 파일에 기록합니다:

#include <Calendar/Appointment.h>
#include <Calendar/AppointmentMsgSaveOptions.h>
#include <Mapi/MapiMessage.h>
#include <Mapi/MapiCalendar.h>
#include <Mapi/MapiCalendarMsgSaveOptions.h>
#include <Mapi/MapiCalendarIcsSaveOptions.h>
#include <Mapi/MapiItemType.h>
#include <system/io/memory_stream.h>
#include <system/console.h>

using namespace System;
using namespace Aspose::Email::Calendar;
using namespace Aspose::Email::Mapi;

// Read the product identifier from an iCalendar file
SharedPtr<Appointment> appointment = Appointment::Load(u"meeting.ics");
Console::WriteLine(u"Appointment product ID: " + appointment->get_ProductId());

// The identifier is kept when the appointment is converted to MSG
auto msgStream = MakeObject<IO::MemoryStream>();
appointment->Save(msgStream, MakeObject<AppointmentMsgSaveOptions>());
msgStream->set_Position(0);
SharedPtr<MapiMessage> msg = MapiMessage::Load(msgStream);

if (msg->get_SupportedType() == MapiItemType::Calendar)
{
    auto calendar = System::DynamicCast<MapiCalendar>(msg->ToMapiMessageItem());
    Console::WriteLine(u"MapiCalendar product ID: " + calendar->get_ProductId());

    // Save the calendar item to MSG with a different product identifier
    auto options = MakeObject<MapiCalendarMsgSaveOptions>();
    options->set_ProductIdentifier(u"-//Contoso//Calendar 2.0//EN");
    calendar->Save(u"meeting_out.msg", options);

    // The identifier set on the item is written to the PRODID field of an ICS file
    calendar->set_ProductId(u"-//Contoso//Calendar 3.0//EN");
    calendar->Save(u"meeting_out.ics", MakeObject<MapiCalendarIcsSaveOptions>());
}

관련 항목