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