Outlook 캘린더 항목 관리

이 문서는 Outlook을 다룹니다 MapiCalendar MSG로 저장된 캘린더 항목. 표준 기반 iCalendar (ICS) 약속 및 회의 요청을 작업하려면, 다음을 참조하십시오 약속 관리; PST 내부에 일정 항목을 저장하고 읽으려면, 다음을 참조하십시오 PST 파일에서 캘린더 항목 관리.

Aspose.Email MapiCalendar 클래스는 캘린더 항목의 다양한 속성을 설정하는 메서드와 속성을 제공합니다. 이 섹션은 다음에 대한 코드 예제를 제공합니다:

캘린더 항목 생성 및 저장

다음 코드 스니펫은 캘린더 항목을 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 캘린더 TimeZone 생성

다음 코드 스니펫은 표준 시간대를 사용해 MapiCalendarTimeZone을 생성하는 방법을 보여줍니다.

MapiCalendarTimeZone timeZone = new MapiCalendarTimeZone(TimeZoneInfo.Local);

약속에 대한 알림 설정

약속이 생성될 때 알림을 추가할 수 있습니다. 이러한 알람은 일정 시작 n분 전, 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 본문을 포함한 약속 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 객체에 조직자를 할당하고 해당 상태를 모두 명시적으로 설정합니다 MeetingReceived 사용하여 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);

관련 항목