Trabajando con elementos del calendario de Outlook usando la biblioteca de correo C++

Trabajando con MapiCalendar

La clase MapiCalendar de Aspose.Email proporciona métodos y atributos para establecer varias propiedades de un elemento de calendario. Este artículo proporciona ejemplos de código para:

  • Crear y guardar elementos de calendario
  • Establecer recordatorios para elementos de MapiCalendar
  • Agregar/Recuperar archivos adjuntos del calendario
  • Recuperar el estado de los destinatarios de solicitudes de reunión
  • Crear un objeto MapiCalendar TimeZone a partir de una zona horaria estándar

Crear y guardar elementos de calendario

El siguiente fragmento de código te muestra cómo crear y guardar un elemento de calendario en formato ICS usando la biblioteca o API de análisis de correo C++.

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

Guardar el elemento del calendario como MSG

El siguiente fragmento de código te muestra cómo guardar el elemento del calendario como 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);

Agregar recordatorio de visualización a un calendario

El siguiente fragmento de código te muestra cómo agregar un recordatorio de visualización a un calendario.

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

Agregar recordatorio de audio a un calendario

El siguiente fragmento de código te muestra cómo agregar un recordatorio de audio a un calendario.

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

Agregar/Recuperar archivos adjuntos de archivos de calendario

El siguiente fragmento de código te muestra cómo agregar/recuperar archivos adjuntos de archivos de calendario.

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

Estado de los destinatarios de una solicitud de reunión

El siguiente fragmento de código te muestra cómo obtener el estado de los destinatarios de una solicitud de reunión.

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

Crear MapiCalendarTimeZone a partir de una zona horaria estándar

El siguiente fragmento de código te muestra cómo crear MapiCalendarTimeZone a partir de una zona horaria estándar.

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

Establecer recordatorio con la cita creada

Un recordatorio puede ser añadido cuando se crea una cita. Estas alarmas pueden activarse en base a diferentes criterios como n minutos antes de que comience el horario, repetir n veces a intervalos de n. Se pueden usar diferentes etiquetas para crear estos disparadores en el script encerrado por BEGIN:VALARM y END:VALARM dentro de una cita. Hay varias variantes en las que se puede establecer un recordatorio en una cita.

Establecer un recordatorio añadiendo etiquetas

El siguiente fragmento de código te muestra cómo establecer un recordatorio añadiendo etiquetas.

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