Working with Outlook Calendar Items using C++ Email Library
Working with MapiCalendar
Aspose.Email’s MapiCalendar class provides methods and attributes to set various properties of a calendar item. This article provides code samples for:
- Creating and saving calendar items
- Setting reminders for MapiCalendar items
- Add/Retrieve Attachments from Calendar
- Retrieving Status of Recipients from Meeting Requests
- Creating MapiCalendar TimeZone object from Standard Timezone
Creating and Saving Calendar items
The following code snippet shows you how to create and save a calendar item in ICS format with C++ Email Parser Library or API.
For complete examples and data files, please go to https://github.com/kashifiqb/Aspose.Email-for-C | |
// The path to the File directory. | |
System::String dataDir = RunExamples::GetDataDir_Outlook(); | |
// Create the appointment | |
System::SharedPtr<MapiCalendar> calendar = System::MakeObject<MapiCalendar>(L"LAKE ARGYLE WA 6743", L"Appointment", L"This is a very important meeting :)", System::DateTime(2012, 10, 2, 13, 0, 0), System::DateTime(2012, 10, 2, 14, 0, 0)); | |
calendar->Save(dataDir + L"CalendarItem_out.ics", Aspose::Email::Mail::AppointmentSaveFormat::Ics); |
Saving the Calendar item as MSG
The following code snippet shows you how to save the calendar item as MSG.
For complete examples and data files, please go to https://github.com/kashifiqb/Aspose.Email-for-C | |
calendar->Save(dataDir + L"CalendarItemAsMSG_out.Msg", Aspose::Email::Mail::AppointmentSaveFormat::Msg); |
Adding display reminder to a Calendar
The following code snippet shows you how to add display reminder to a calendar.
For complete examples and data files, please go to https://github.com/kashifiqb/Aspose.Email-for-C | |
// The path to the File directory. | |
System::String dataDir = RunExamples::GetDataDir_Outlook(); | |
// Create Appointment | |
System::SharedPtr<Appointment> app = System::MakeObject<Appointment>(L"Home", System::DateTime::get_Now().AddHours(1), System::DateTime::get_Now().AddHours(1), MailAddress::to_MailAddress(L"organizer@domain.com"), MailAddressCollection::to_MailAddressCollection(L"attendee@gmail.com")); | |
System::SharedPtr<MailMessage> msg = System::MakeObject<MailMessage>(); | |
msg->AddAlternateView(app->RequestApointment()); | |
System::SharedPtr<MapiMessage> mapi = MapiMessage::FromMailMessage(msg); | |
System::SharedPtr<MapiCalendar> calendar = System::DynamicCast<Aspose::Email::Outlook::MapiCalendar>(mapi->ToMapiMessageItem()); | |
// Set calendar Properties | |
calendar->set_ReminderSet(true); | |
calendar->set_ReminderDelta(45); | |
//45 min before start of event | |
System::String savedFile = (dataDir + L"calendarWithDisplayReminder.ics"); | |
calendar->Save(savedFile, Aspose::Email::Mail::AppointmentSaveFormat::Ics); |
Adding audio reminder to a Calendar
The following code snippet shows you how to add audio reminder to a calendar.
For complete examples and data files, please go to https://github.com/kashifiqb/Aspose.Email-for-C | |
// The path to the File directory. | |
System::String dataDir = RunExamples::GetDataDir_Outlook(); | |
System::SharedPtr<Appointment> app = System::MakeObject<Appointment>(L"Home", System::DateTime::get_Now().AddHours(1), System::DateTime::get_Now().AddHours(1), MailAddress::to_MailAddress(L"organizer@domain.com"), MailAddressCollection::to_MailAddressCollection(L"attendee@gmail.com")); | |
System::SharedPtr<MailMessage> msg = System::MakeObject<MailMessage>(); | |
msg->AddAlternateView(app->RequestApointment()); | |
System::SharedPtr<MapiMessage> mapi = MapiMessage::FromMailMessage(msg); | |
System::SharedPtr<MapiCalendar> calendar = System::DynamicCast<Aspose::Email::Outlook::MapiCalendar>(mapi->ToMapiMessageItem()); | |
// Set calendar properties | |
calendar->set_ReminderSet(true); | |
calendar->set_ReminderDelta(58); | |
//58 min before start of event | |
calendar->set_ReminderFileParameter(dataDir + L"Alarm01.wav"); | |
System::String savedFile = (dataDir + L"calendarWithAudioReminder_out.ics"); | |
calendar->Save(savedFile, Aspose::Email::Mail::AppointmentSaveFormat::Ics); |
Add/Retrieve attachments from Calendar files
The following code snippet shows you how to add/retrieve attachments from calendar files.
For complete examples and data files, please go to https://github.com/kashifiqb/Aspose.Email-for-C | |
System::ArrayPtr<System::String> files = System::MakeArray<System::String>(3); | |
files[0] = dataDir + L"attachment_1.doc"; | |
files[1] = dataDir + L"download.png"; | |
files[2] = dataDir + L"Desert.jpg"; | |
System::SharedPtr<Appointment> app1 = System::MakeObject<Appointment>(L"Home", System::DateTime::get_Now().AddHours(1), System::DateTime::get_Now().AddHours(1), MailAddress::to_MailAddress(L"organizer@domain.com"), MailAddressCollection::to_MailAddressCollection(L"attendee@gmail.com")); | |
{ | |
for (int i_ = 0; i_ < files->Count(); ++i_) | |
{ | |
System::String file = files[i_]; | |
{ | |
{ | |
System::SharedPtr<System::IO::MemoryStream> ms = System::MakeObject<System::IO::MemoryStream>(System::IO::File::ReadAllBytes(file)); | |
app1->get_Attachments()->Add(System::MakeObject<Attachment>(ms, System::IO::Path::GetFileName(file))); | |
} | |
} | |
} | |
} | |
app1->Save(dataDir + L"appWithAttachments_out.ics", Aspose::Email::Mail::AppointmentSaveFormat::Ics); | |
System::SharedPtr<Appointment> app2 = Appointment::Load(dataDir + L"appWithAttachments_out.ics"); | |
System::Console::WriteLine(app2->get_Attachments()->get_Count()); | |
{ | |
auto att_enumerator = (app2->get_Attachments())->GetEnumerator(); | |
decltype(att_enumerator->get_Current()) att; | |
while (att_enumerator->MoveNext() && (att = att_enumerator->get_Current(), true)) | |
{ | |
System::Console::WriteLine(att->get_Name()); | |
} | |
} |
Status of Recipients from a Meeting Request
The following code snippet shows you how to status of recipients from a meeting request.
For complete examples and data files, please go to https://github.com/kashifiqb/Aspose.Email-for-C | |
System::SharedPtr<MapiMessage> message = MapiMessage::FromFile(fileName); | |
{ | |
auto recipient_enumerator = (message->get_Recipients())->GetEnumerator(); | |
decltype(recipient_enumerator->get_Current()) recipient; | |
while (recipient_enumerator->MoveNext() && (recipient = recipient_enumerator->get_Current(), true)) | |
{ | |
System::Console::WriteLine(System::ObjectExt::Box<MapiRecipientTrackStatus>(recipient->get_RecipientTrackStatus())); | |
} | |
} |
Create MapiCalendarTimeZone from Standard Timezone
The following code snippet shows you how to Create MapiCalendarTimeZone from standard Timezone.
For complete examples and data files, please go to https://github.com/kashifiqb/Aspose.Email-for-C | |
System::SharedPtr<MapiCalendarTimeZone> timeZone = System::MakeObject<MapiCalendarTimeZone>(System::TimeZoneInfo::get_Local()); |
Setting Reminder with the Created Appointment
A reminder can be added when an appointment is created. These alarms can trigger based on different criteria like n minutes before the schedule starts, repeat n times at n intervals. Different tags can be used to create these triggers in the script enclosed by BEGIN:VALARM and END:VALARM within an appointment. There are a number of variants in which the reminder can be set on an appointment.
Setting a Reminder by Adding Tags
The following code snippet shows you how to Set a reminder by adding tags.