Manage Appointments: Create, Load, Convert ICS and Work with Recurrences

Meeting invitations, calendar exports and scheduling data all travel as iCalendar (ICS) files. In Aspose.Email for C++ a single VEVENT is represented by the Appointment class of the Aspose::Email::Calendar namespace; recurrence rules live in Aspose::Email::Calendar::Recurrences. This article stays with the standards-based side of calendaring. Outlook-specific MapiCalendar items are covered in Working with Outlook Calendar Items, and calendar items stored in a PST in Working with Calendar Items in PST File.

The samples below use the following headers and namespaces:

#include <MailMessage.h>
#include <MailAddress.h>
#include <MailAddressCollection.h>
#include <AlternateView.h>
#include <AlternateViewCollection.h>
#include <ParticipationStatus.h>
#include <SaveOptions.h>
#include <EmlSaveOptions.h>
#include <Mime/ContentType.h>
#include <Mapi/MapiMessage.h>
#include <Calendar/Appointment.h>
#include <Calendar/AppointmentIcsSaveOptions.h>
#include <Calendar/AppointmentMsgSaveOptions.h>
#include <Calendar/AppointmentMethodType.h>
#include <Calendar/AppointmentAction.h>
#include <Calendar/CalendarReader.h>
#include <Calendar/CalendarWriter.h>
#include <Calendar/Recurrences/CalendarRecurrence.h>
#include <Calendar/Recurrences/RecurrenceRule.h>
#include <Calendar/Recurrences/RecurrenceRuleCollection.h>
#include <Calendar/Recurrences/ByNumberCollection.h>
#include <Calendar/Recurrences/DateCollection.h>
#include <Calendar/Recurrences/WeeklyRecurrencePattern.h>
#include <Calendar/Recurrences/CalendarDay.h>
#include <Calendar/Recurrences/Frequency.h>
#include <system/guid.h>
#include <system/collections/list.h>
#include <system/convert.h>

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

Create an Appointment and Save It as ICS or MSG

The seven-argument Appointment constructor takes the location, summary, description, start and end times, the organizer as a MailAddress and the attendees as a MailAddressCollection. Save writes the result in the format selected by the options object: AppointmentIcsSaveOptions for an ICS file that any calendar application imports, or AppointmentMsgSaveOptions for an Outlook MSG item.

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

SharedPtr<Appointment> appointment = MakeObject<Appointment>(
    u"Meeting Room 3 at Office Headquarters",      // location
    u"Monthly Meeting",                             // summary
    u"Please confirm your availability.",           // description
    DateTime(2025, 2, 8, 13, 0, 0),                 // start date
    DateTime(2025, 2, 8, 14, 0, 0),                 // end date
    MakeObject<MailAddress>(u"organizer@domain.com"), // organizer
    attendees);                                     // attendees

// iCalendar (ICS) output
appointment->Save(u"MonthlyMeeting.ics", MakeObject<AppointmentIcsSaveOptions>());

// Outlook MSG output
appointment->Save(u"MonthlyMeeting.msg", MakeObject<AppointmentMsgSaveOptions>());

Add an HTML Description

iCalendar allows an alternative, richer rendering of the description through the X-ALT-DESC property. Assign the markup to HtmlDescription; clients that understand the property show the HTML, all others fall back to the plain DESCRIPTION. The shorter five-argument constructor used here omits the summary and description.

SharedPtr<MailAddressCollection> attendees = MakeObject<MailAddressCollection>();
attendees->Add(MakeObject<MailAddress>(u"AinaMartensson@to.com", String(u"Aina Martensson")));

SharedPtr<Appointment> appointment = MakeObject<Appointment>(
    u"Bygget 83",
    DateTime::get_UtcNow(),                 // start date
    DateTime::get_UtcNow().AddHours(1),     // end date
    MakeObject<MailAddress>(u"TintinStrom@from.com", String(u"Tintin Strom")), // organizer
    attendees);

// alternative representation of the description, written as X-ALT-DESC
appointment->set_HtmlDescription(
    u"<html>"
    u"<style type=\"text/css\">.text { font-family:'Comic Sans MS'; font-size:16px; }</style>"
    u"<body><p class=\"text\">Hi, I'm happy to invite you to our party.</p></body>"
    u"</html>");

appointment->Save(u"PartyInvitation.ics", MakeObject<AppointmentIcsSaveOptions>());

Create a Draft Meeting Request

A meeting request is an appointment embedded in a mail message as a text/calendar alternate view. To keep it as a draft that can be completed later - in Outlook, for example - set MethodType to AppointmentMethodType::Publish, attach the view produced by RequestApointment to a MailMessage, convert the message to MAPI and save it as MSG.

String sender = u"test@gmail.com";
String recipient = u"test@email.com";

SharedPtr<MailMessage> message = MakeObject<MailMessage>(sender, recipient, String::Empty, String::Empty);

SharedPtr<MailAddressCollection> attendees = MakeObject<MailAddressCollection>();
attendees->Add(MakeObject<MailAddress>(recipient));

SharedPtr<Appointment> appointment = MakeObject<Appointment>(String::Empty, DateTime::get_Now(), DateTime::get_Now(),
    MakeObject<MailAddress>(sender), attendees);

// PUBLISH marks the request as a draft that can be completed later
appointment->set_MethodType(AppointmentMethodType::Publish);

message->AddAlternateView(appointment->RequestApointment());

SharedPtr<MapiMessage> msg = MapiMessage::FromMailMessage(message);
msg->Save(u"DraftAppointment.msg");

Create a Draft from iCalendar Text

If the invitation already exists as iCalendar text - received from another system, or produced by a template - it can be wrapped into an AlternateView with CreateAlternateViewFromString and a text/calendar ContentType, then stored the same way.

String ical =
    u"BEGIN:VCALENDAR\r\n"
    u"METHOD:PUBLISH\r\n"
    u"PRODID:-//Aspose Ltd//iCalender Builder (v3.0)//EN\r\n"
    u"VERSION:2.0\r\n"
    u"BEGIN:VEVENT\r\n"
    u"ATTENDEE;CN=test@gmail.com:mailto:test@gmail.com\r\n"
    u"DTSTART:20130220T171439\r\n"
    u"DTEND:20130220T174439\r\n"
    u"DTSTAMP:20130220T161439Z\r\n"
    u"END:VEVENT\r\n"
    u"END:VCALENDAR";

SharedPtr<MailMessage> message = MakeObject<MailMessage>(u"test@gmail.com", u"test@email.com", String::Empty, String::Empty);

// the iCalendar text becomes a text/calendar alternate view of the message
SharedPtr<AlternateView> view = AlternateView::CreateAlternateViewFromString(ical, MakeObject<ContentType>(u"text/calendar"));
message->get_AlternateViews()->Add(view);

SharedPtr<MapiMessage> msg = MapiMessage::FromMailMessage(message);
msg->Save(u"DraftFromText.msg");

Customize an Appointment

Set the Participation Status of Attendees

When an appointment is written back as a reply, each attendee can carry a PARTSTAT value. Assign a ParticipationStatus to the MailAddress objects before they are added to the attendee collection; the value appears as a parameter of the corresponding ATTENDEE line.

DateTime startDate(2025, 12, 10, 10, 12, 11);
DateTime endDate(2025, 12, 13, 13, 11, 12);
SharedPtr<MailAddress> organizer = MakeObject<MailAddress>(u"aaa@amail.com", String(u"Organizer"));

SharedPtr<MailAddress> attendee1 = MakeObject<MailAddress>(u"bbb@bmail.com", String(u"First attendee"));
SharedPtr<MailAddress> attendee2 = MakeObject<MailAddress>(u"ccc@cmail.com", String(u"Second attendee"));

// the status ends up in the PARTSTAT parameter of each ATTENDEE line
attendee1->set_ParticipationStatus(ParticipationStatus::Accepted);
attendee2->set_ParticipationStatus(ParticipationStatus::Declined);

SharedPtr<MailAddressCollection> attendees = MakeObject<MailAddressCollection>();
attendees->Add(attendee1);
attendees->Add(attendee2);

SharedPtr<Appointment> appointment = MakeObject<Appointment>(u"Room 12", startDate, endDate, organizer, attendees);
appointment->Save(u"WithParticipationStatus.ics", MakeObject<AppointmentIcsSaveOptions>());

Set the Product Identifier

Every iCalendar file names the software that produced it in its PRODID property. To publish your own identifier, set ProductId on the save options - the static Default instance is a convenient starting point.

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

SharedPtr<Appointment> appointment = MakeObject<Appointment>(u"location", u"test appointment", u"Test Description",
    DateTime::get_Today(), DateTime::get_Today().AddDays(1), MakeObject<MailAddress>(u"first@test.com"), attendees);

// the value is written to the PRODID property of the calendar
SharedPtr<AppointmentIcsSaveOptions> saveOptions = AppointmentIcsSaveOptions::get_Default();
saveOptions->set_ProductId(u"Test Corporation");

appointment->Save(u"CustomProdId.ics", saveOptions);

Load an Appointment

The static Load method parses an ICS file (a stream overload exists as well) and returns an Appointment whose properties reflect the VEVENT.

SharedPtr<Appointment> loaded = Appointment::Load(u"MonthlyMeeting.ics");

Console::WriteLine(u"Summary: " + loaded->get_Summary());
Console::WriteLine(u"Location: " + loaded->get_Location());
Console::WriteLine(u"Description: " + loaded->get_Description());
Console::WriteLine(u"Start date: " + loaded->get_StartDate().ToString());
Console::WriteLine(u"End date: " + loaded->get_EndDate().ToString());
Console::WriteLine(u"Organizer: " + loaded->get_Organizer()->ToString());
Console::WriteLine(u"Attendees: " + loaded->get_Attendees()->ToString());

Convert ICS to EML or MSG

ToMailMessage wraps the appointment into a MIME message with a calendar alternate view, and ToMapiMessage produces an Outlook item. Either result can be saved with the usual methods.

SharedPtr<Appointment> appointment = Appointment::Load(u"MonthlyMeeting.ics");

// MIME message carrying the invitation
SharedPtr<MailMessage> eml = appointment->ToMailMessage();
eml->Save(u"MonthlyMeeting.eml", SaveOptions::get_DefaultEml());

// Outlook MAPI message
SharedPtr<MapiMessage> msg = appointment->ToMapiMessage();
msg->Save(u"MonthlyMeetingFromIcs.msg");

Check the iCalendar Version

Version returns the VERSION property of the loaded file - "2.0" for iCalendar (RFC 5545), "1.0" for the older vCalendar format - so an application can branch on the dialect it received.

SharedPtr<Appointment> appointment = Appointment::Load(u"MonthlyMeeting.ics");

// Version holds the ICS/VCS version string, e.g. "2.0" for iCalendar
if (appointment->get_Version() == u"2.0")
{
    Console::WriteLine(u"iCalendar 2.0 file");
}

Read Multiple Events from an ICS File

Calendar exports often bundle many events in one file. CalendarReader iterates through them: NextEvent advances to the following VEVENT and returns false at the end, while Current exposes the event as an Appointment.

auto appointments = MakeObject<Collections::Generic::List<SharedPtr<Appointment>>>();

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

// each call moves to the next VEVENT; Current exposes it as an Appointment
while (reader->NextEvent())
{
    appointments->Add(reader->get_Current());
}

Console::WriteLine(u"Events loaded: " + Convert::ToString(appointments->get_Count()));
for (SharedPtr<Appointment> appointment : appointments)
{
    Console::WriteLine(appointment->get_StartDate().ToString(u"yyyy-MM-dd") + u"  " + appointment->get_Summary());
}

Write Multiple Events to an ICS File

CalendarWriter is the counterpart for output: every Write call appends one VEVENT to the same VCALENDAR. The Action of the save options decides the METHOD written to the file. Dispose the writer to close the calendar properly.

SharedPtr<AppointmentIcsSaveOptions> saveOptions = MakeObject<AppointmentIcsSaveOptions>();
saveOptions->set_Action(AppointmentAction::Create);

SharedPtr<CalendarWriter> writer = MakeObject<CalendarWriter>(u"MultipleEvents.ics", saveOptions);

for (int32_t i = 0; i < 10; i++)
{
    SharedPtr<MailAddressCollection> attendees = MakeObject<MailAddressCollection>();
    attendees->Add(MakeObject<MailAddress>(u"receiver@domain.com"));

    SharedPtr<Appointment> appointment = MakeObject<Appointment>(String::Empty,
        DateTime::get_Now().AddDays(i), DateTime::get_Now().AddDays(i).AddHours(1),
        MakeObject<MailAddress>(u"sender@domain.com"), attendees);
    appointment->set_Description(u"Test body " + Convert::ToString(i));
    appointment->set_Summary(u"Test summary:" + Convert::ToString(i));

    // every call appends one VEVENT to the same VCALENDAR
    writer->Write(appointment);
}

writer->Dispose();

Create a Recurring Appointment

A series of meetings is a single appointment with a recurrence pattern attached to its Recurrence property. The pattern classes - DailyRecurrencePattern, WeeklyRecurrencePattern, MonthlyRecurrencePattern, YearlyRecurrencePattern - are constructed either with the number of occurrences or with an end date. Assigning a UniqueId is good practice: the same identifier is required later to issue an update or a cancellation for the series. The example creates 14 meetings held on Monday, Tuesday and Thursday of every week and saves the series as ICS.

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

DateTime startDate(2025, 12, 1, 17, 0, 0);
DateTime endDate(2025, 12, 1, 17, 30, 0);
SharedPtr<Appointment> appointment = MakeObject<Appointment>(u"same place", startDate, endDate,
    MakeObject<MailAddress>(u"from@domain.com"), attendees);

// keep the identifier so the series can be updated or cancelled later
appointment->set_UniqueId(Guid::NewGuid().ToString());
appointment->set_Description(u"Weekly sync");

// 14 occurrences on Monday, Tuesday and Thursday of every week
SharedPtr<WeeklyRecurrencePattern> pattern = MakeObject<WeeklyRecurrencePattern>(14);
pattern->set_StartDays(MakeArray<CalendarDay>({ CalendarDay::Monday, CalendarDay::Tuesday, CalendarDay::Thursday }));
pattern->set_Interval(1);

appointment->set_Recurrence(pattern);

appointment->Save(u"RecurringMeeting.ics", MakeObject<AppointmentIcsSaveOptions>());

The resulting file contains RRULE:FREQ=WEEKLY;WKST=MO;INTERVAL=1;COUNT=14;BYDAY=MO,TU,TH. The alternate views returned by UpdateAppointment and CancelAppointment are built the same way as RequestApointment and can be attached to a message that is then sent with one of the mail clients.

Work with iCalendar Recurrence Patterns

In iCalendar terms, a recurrence pattern is a compact description of a schedule from which the individual dates - the occurrences - can be computed. RFC 5545 expresses it with a handful of properties: DTSTART (the first occurrence and anchor of the pattern), RRULE (the repeating rule), RDATE (extra dates to include), EXRULE (a rule describing dates to exclude) and EXDATE (individual dates to exclude). Only DTSTART is mandatory.

The Aspose::Email::Calendar::Recurrences namespace models this directly:

Parse a Pattern and Generate Its Occurrences

The CalendarRecurrence(String) constructor accepts iCalendar text; GenerateOccurrences expands it into a DateCollection. Ten team meetings, every Monday at 10:00:

// Ten team meetings, every Monday at 10am
SharedPtr<CalendarRecurrence> pattern = MakeObject<CalendarRecurrence>(
    u"DTSTART:20040301T100000\nRRULE:FREQ=WEEKLY;COUNT=10;BYDAY=MO");

SharedPtr<DateCollection> dates = pattern->GenerateOccurrences();

for (DateTime date : dates)
{
    Console::WriteLine(date.ToString());
}

Build a Pattern in Code

The same result can be reached without text: set the start date, add a rule to RRules and fill in its properties. The GenerateOccurrences(int32_t) overload limits the number of dates produced, which is the way to ask for “the next N” occurrences of an unbounded rule.

SharedPtr<CalendarRecurrence> recurrencePattern = MakeObject<CalendarRecurrence>();
recurrencePattern->set_StartDate(DateTime(1997, 9, 10, 9, 0, 0));

// build the RRULE part programmatically
SharedPtr<RecurrenceRule> rule = recurrencePattern->get_RRules()->Add();
rule->set_Frequency(Frequency::Monthly);
rule->set_Count(20);
rule->set_Interval(18);
rule->get_ByMonthDay()->Add(MakeArray<int32_t>({ 10, 11, 12, 13, 14, 15 }));

SharedPtr<DateCollection> expectedDates = recurrencePattern->GenerateOccurrences(20);
Console::WriteLine(u"expectedDates.Count = " + Convert::ToString(expectedDates->get_Count()));

for (DateTime date : expectedDates)
{
    Console::WriteLine(u"DateTime = " + date.ToString());
}

Describe a Rule in Plain Words

FriendlyText turns a rule into a sentence suitable for a user interface. The rule below yields “Recur every month on the 1st and 1st from end day(s) of the month for a maximum of 2 occurrences.”

SharedPtr<RecurrenceRule> rule = MakeObject<RecurrenceRule>();
rule->set_Frequency(Frequency::Monthly);
rule->set_Count(2);
rule->get_ByMonthDay()->Add(1);
rule->get_ByMonthDay()->Add(-1);

Console::WriteLine(rule->get_FriendlyText());

Rule Cookbook

Schedule RRULE
Last day of every month (-2 would be the day before; 31 skips shorter months) FREQ=MONTHLY;BYMONTHDAY=-1
Last working day of every month (BYSETPOS picks the last of the listed weekdays) FREQ=MONTHLY;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=-1
Last Monday of the year FREQ=YEARLY;BYDAY=-1MO
Friday of the first ISO 8601 week of the year FREQ=YEARLY;BYWEEKNO=1;BYDAY=FR
First Friday of the year FREQ=YEARLY;BYDAY=1FR

Date and Time Values in Patterns

  • A DATE value has the form yyyyMMdd (19970714).
  • A local DATE-TIME (DTSTART:19980118T230000) is “floating”: it denotes the same wall-clock time in whatever time zone is current.
  • A UTC DATE-TIME carries a trailing Z (DTSTART:19980119T070000Z). Aspose.Email ignores the Z and treats the value as local time; in UNTIL, where RFC 5545 requires UTC, any of the forms is accepted.
  • A DATE-TIME qualified with TZID (DTSTART;TZID=US-Eastern:19980119T020000) is also treated as local time; the TZID parameter is currently ignored.
  • BYWEEKNO follows ISO 8601: week 1 is the first week with at least four days in the new year. It is valid only with FREQ=YEARLY, and its values range from 1 to 53 and from -1 to -53.

See Also