Работа с элементами календаря Outlook с использованием библиотеки электронной почты C++

Работа с MapiCalendar

Класс MapiCalendar библиотеки Aspose.Email предоставляет методы и атрибуты для настройки различных свойств элемента календаря. В этой статье приведены примеры кода для:

  • Создания и сохранения элементов календаря
  • Установки напоминаний для элементов MapiCalendar
  • Добавления/извлечения вложений из календаря
  • Получения статуса получателей из запросов на встречу
  • Создания объекта MapiCalendar TimeZone из стандартного часового пояса

Создание и сохранение элементов календаря

Следующий фрагмент кода показывает, как создать и сохранить элемент календаря в формате ICS с использованием библиотеки или API C++ Email Parser.

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);

Сохранение элемента календаря в формате MSG

Следующий фрагмент кода показывает, как сохранить элемент календаря в формате 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);

Добавление дисплейного напоминания в календарь

Следующий фрагмент кода показывает, как добавить дисплейное напоминание в календарь.

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);

Добавление аудионапоминания в календарь

Следующий фрагмент кода показывает, как добавить аудионапоминание в календарь.

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);

Добавление/извлечение вложений из файлов календаря

Следующий фрагмент кода показывает, как добавлять/извлекать вложения из файлов календаря.

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());
}
}

Статус получателей из запроса на встречу

Следующий фрагмент кода показывает, как получить статус получателей из запроса на встречу.

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()));
}
}

Создание MapiCalendarTimeZone из стандартного часового пояса

Следующий фрагмент кода показывает, как создать MapiCalendarTimeZone из стандартного часового пояса.

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());

Установка напоминания с созданной встречей

Напоминание может быть добавлено при создании встречи. Эти сигнализации могут срабатывать на основе различных критериев, таких как n минут до начала расписания, повторение n раз с интервалами в n. Для создания этих триггеров в сценарии можно использовать различные теги, заключенные между BEGIN:VALARM и END:VALARM внутри встречи. Существует несколько вариантов, при которых напоминание может быть установлено для встречи.

Установка напоминания путем добавления тегов

Следующий фрагмент кода показывает, как установить напоминание, добавляя теги.

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::String location = L"Meeting Location: Room 5";
System::DateTime startDate(1997, 3, 18, 18, 30, 00), endDate(1997, 3, 18, 19, 30, 00);
System::SharedPtr<MailAddress> organizer = System::MakeObject<MailAddress>(L"aaa@amail.com", L"Organizer");
System::SharedPtr<MailAddressCollection> attendees = System::MakeObject<MailAddressCollection>();
attendees->Add(System::MakeObject<MailAddress>(L"bbb@bmail.com", L"First attendee"));
System::SharedPtr<Appointment> target = System::MakeObject<Appointment>(location, startDate, endDate, organizer, attendees);
// Audio alarm that will sound at a precise time and
// Repeat 4 more times at 15 minute intervals:
System::SharedPtr<AppointmentReminder> audioReminder = System::MakeObject<AppointmentReminder>();
audioReminder->set_Trigger(System::MakeObject<ReminderTrigger>(System::DateTime(1997, 3, 17, 13, 30, 0, System::DateTimeKind::Utc)));
audioReminder->set_Repeat(4);
audioReminder->set_Duration(System::MakeObject<ReminderDuration>(System::TimeSpan(0, 15, 0)));
audioReminder->set_Action(Aspose::Email::Mail::ReminderAction::Audio);
System::SharedPtr<ReminderAttachment> attach = System::MakeObject<ReminderAttachment>(System::MakeObject<System::Uri>(L"ftp://Host.com/pub/sounds/bell-01.aud"));
audioReminder->get_Attachments()->Add(attach);
target->get_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:
System::SharedPtr<AppointmentReminder> displayReminder = System::MakeObject<AppointmentReminder>();
System::SharedPtr<ReminderDuration> dur = System::MakeObject<ReminderDuration>(System::TimeSpan(0, -30, 0));
displayReminder->set_Trigger(System::MakeObject<ReminderTrigger>(dur, Aspose::Email::Mail::ReminderRelated::Start));
displayReminder->set_Repeat(2);
displayReminder->set_Duration(System::MakeObject<ReminderDuration>(System::TimeSpan(0, 15, 0)));
displayReminder->set_Action(Aspose::Email::Mail::ReminderAction::Display);
displayReminder->set_Description(L"Breakfast meeting with executive team at 8:30 AM EST");
target->get_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.
System::SharedPtr<AppointmentReminder> emailReminder = System::MakeObject<AppointmentReminder>();
System::SharedPtr<ReminderDuration> dur1 = System::MakeObject<ReminderDuration>(System::TimeSpan(-2, 0, 0, 0));
emailReminder->set_Trigger(System::MakeObject<ReminderTrigger>(dur1, Aspose::Email::Mail::ReminderRelated::Start));
System::SharedPtr<ReminderAttendee> attendee = System::MakeObject<ReminderAttendee>(L"john_doe@host.com");
emailReminder->get_Attendees()->Add(attendee);
emailReminder->set_Action(Aspose::Email::Mail::ReminderAction::Email);
emailReminder->set_Summary(L"REMINDER: SEND AGENDA FOR WEEKLY STAFF MEETING");
emailReminder->set_Description(L"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.");
System::SharedPtr<ReminderAttachment> attach1 = System::MakeObject<ReminderAttachment>(System::MakeObject<System::Uri>(L"http://Host.com/templates/agenda.doc"));
emailReminder->get_Attachments()->Add(attach1);
target->get_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.
System::SharedPtr<AppointmentReminder> procReminder = System::MakeObject<AppointmentReminder>();
procReminder->set_Trigger(System::MakeObject<ReminderTrigger>(System::DateTime(1998, 1, 1, 5, 0, 0, System::DateTimeKind::Utc)));
procReminder->set_Repeat(23);
procReminder->set_Duration(System::MakeObject<ReminderDuration>(System::TimeSpan(1, 0, 0)));
procReminder->set_Action(Aspose::Email::Mail::ReminderAction::Procedure);
System::SharedPtr<ReminderAttachment> attach2 = System::MakeObject<ReminderAttachment>(System::MakeObject<System::Uri>(L"ftp://Host.com/novo-procs/felizano.exe"));
procReminder->get_Attachments()->Add(attach2);
target->get_Reminders()->Add(procReminder);
target->Save(dataDir + L"savedFile_out.ics");