Trabalhando com Itens de Calendário do Outlook usando a Biblioteca de Email C++

Trabalhando com MapiCalendar

A classe MapiCalendar da Aspose.Email fornece métodos e atributos para definir várias propriedades de um item de calendário. Este artigo fornece exemplos de código para:

  • Criar e salvar itens de calendário
  • Definir lembretes para itens MapiCalendar
  • Adicionar/Recuperar Anexos de Calendário
  • Recuperar Status dos Destinatários de Solicitações de Reunião
  • Criar objeto MapiCalendar TimeZone a partir de Fuso Horário Padrão

Criando e Salvando Itens de Calendário

O seguinte trecho de código mostra como criar e salvar um item de calendário no formato ICS usando a Biblioteca ou API de Análise de Email 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);

Salvando o Item de Calendário como MSG

O seguinte trecho de código mostra como salvar o item de calendário 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);

Adicionando lembrete visual a um Calendário

O seguinte trecho de código mostra como adicionar um lembrete visual a um calendário.

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

Adicionando lembrete de áudio a um Calendário

O seguinte trecho de código mostra como adicionar um lembrete de áudio a um calendário.

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

Adicionar/Recuperar anexos de arquivos de Calendário

O seguinte trecho de código mostra como adicionar/recuperar anexos de arquivos de calendário.

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 dos Destinatários de uma Solicitação de Reunião

O seguinte trecho de código mostra como obter o status dos destinatários de uma solicitação de reunião.

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

Criar MapiCalendarTimeZone a partir de Fuso Horário Padrão

O seguinte trecho de código mostra como criar MapiCalendarTimeZone a partir de um fuso horário padrão.

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

Definindo Lembrete com o Compromisso Criado

Um lembrete pode ser adicionado quando um compromisso é criado. Esses alarmes podem ser acionados com base em diferentes critérios, como n minutos antes do horário programado, repetir n vezes em n intervalos. Diferentes tags podem ser usadas para criar esses gatilhos no script delimitado por BEGIN:VALARM e END:VALARM dentro de um compromisso. Existem várias variantes nas quais o lembrete pode ser definido em um compromisso.

Definindo um Lembrete Adicionando Tags

O seguinte trecho de código mostra como definir um lembrete adicionando tags.

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