Trabalhando com Tarefas do Outlook

Criando, Salvando e Lendo Tarefas

Aspose.Email para C++ permite que você crie tarefas do Outlook e as salve no formato MSG. A classe MapiTask fornece uma série de propriedades, como Percentcomplete, Estimatedeffort, ActualEffort, History, LastUpdate, entre outras, para acomodar e definir informações necessárias para uma tarefa do Outlook. Este artigo mostra como criar, salvar e ler uma MapiTask do disco. Para criar e salvar uma tarefa no disco:

  1. Instanciar um novo objeto da classe MapiTask.
  2. Inserir informações sobre as propriedades da tarefa.
  3. Salvar a tarefa no disco no formato MSG.

O seguinte trecho de código mostra como criar, salvar e ler Tarefas.

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<MapiTask> task = System::MakeObject<MapiTask>(L"To Do", L"Just click and type to add new task", System::DateTime::get_Now(), System::DateTime::get_Now().AddDays(3));
task->set_PercentComplete(20);
task->set_EstimatedEffort(2000);
task->set_ActualEffort(20);
task->set_History(Aspose::Email::Outlook::MapiTaskHistory::Assigned);
task->set_LastUpdate(System::DateTime::get_Now());
task->get_Users()->set_Owner(L"Darius");
task->get_Users()->set_LastAssigner(L"Harkness");
task->get_Users()->set_LastDelegate(L"Harkness");
task->get_Users()->set_Ownership(Aspose::Email::Outlook::MapiTaskOwnership::AssignersCopy);
task->set_Companies(System::MakeArray<System::String>({L"company1", L"company2", L"company3"}));
task->set_Categories(System::MakeArray<System::String>({L"category1", L"category2", L"category3"}));
task->set_Mileage(L"Some test mileage");
task->set_Billing(L"Test billing information");
task->get_Users()->set_Delegator(L"Test Delegator");
task->set_Sensitivity(Aspose::Email::Outlook::Pst::MapiSensitivity::Personal);
task->set_Status(Aspose::Email::Outlook::MapiTaskStatus::Complete);
task->set_EstimatedEffort(5);
task->Save(dataDir + L"MapiTask.msg", Aspose::Email::Outlook::TaskSaveFormat::Msg);

Lendo uma MapiTask

O objeto da classe MapiTask é usado para converter o objeto MapiMessage que carrega uma tarefa do disco no formato MSG. O seguinte trecho de código mostra como ler uma MapiTask.

For complete examples and data files, please go to https://github.com/kashifiqb/Aspose.Email-for-C
System::SharedPtr<MapiMessage> msg = MapiMessage::FromFile(dataDir + L"Contact.msg");
System::SharedPtr<MapiContact> mapiContact = System::DynamicCast<Aspose::Email::Outlook::MapiContact>(msg->ToMapiMessageItem());

Lendo uma Tarefa VToDo

As Tarefas do Google exportadas no formato iCalendar como eventos VToDo podem ser carregadas usando a classe MapiTask, como mostrado no seguinte exemplo de código. O seguinte trecho de código mostra como ler uma Tarefa VToDo.

For complete examples and data files, please go to https://github.com/kashifiqb/Aspose.Email-for-C
System::SharedPtr<MapiTask> task = MapiTask::FromVTodo(dataDir + L"VToDoTask.ics");
task->Save(dataDir + L"VToDo_out.msg", Aspose::Email::Outlook::TaskSaveFormat::Msg);

Adicionando Informações de Lembrete a uma MapiTask

Semelhante ao Microsoft Outlook, Aspose.Email pode adicionar informações de lembrete a uma MapiTask. O seguinte trecho de código mostra como adicionar informações de lembrete a uma MapiTask.

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 MapiTask and set Task Properties
System::SharedPtr<MapiTask> testTask = System::MakeObject<MapiTask>(L"task with reminder", L"this is a body", System::DateTime::get_Now(), System::DateTime::get_Now().AddHours(1));
testTask->set_ReminderSet(true);
testTask->set_ReminderTime(System::DateTime::get_Now());
testTask->set_ReminderFileParameter(dataDir + L"Alarm01.wav");
testTask->Save(dataDir + L"AddReminderInformationToMapiTask_out", Aspose::Email::Outlook::TaskSaveFormat::Msg);

Adicionando Anexos a uma MapiTask

O seguinte trecho de código mostra como adicionar anexos a uma MapiTask.

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 attachmentContent = L"Test attachment body";
System::String attachmentName = L"Test attachment name";
System::SharedPtr<MapiTask> testTask = System::MakeObject<MapiTask>(L"Task with attacment", L"Test body of task with attacment", System::DateTime::get_Now(), System::DateTime::get_Now().AddHours(1));
testTask->get_Attachments()->Add(attachmentName, System::Text::Encoding::get_Unicode()->GetBytes(attachmentContent));
testTask->Save(dataDir + L"AddAttachmentsToMapiTask_out", Aspose::Email::Outlook::TaskSaveFormat::Msg);

Adicionando Recorrência a MapiTask

Aspose.Email permite criar uma tarefa recorrente onde a recorrência pode ser diária, semanal, mensal ou anual. O seguinte trecho de código mostra como criar uma tarefa com diferentes tipos de recorrência.

For complete examples and data files, please go to https://github.com/kashifiqb/Aspose.Email-for-C
System::DateTime startDate(2015, 4, 30, 10, 00, 00);
System::SharedPtr<MapiTask> task = System::MakeObject<MapiTask>(L"abc", L"def", startDate, startDate.AddHours(1));
task->set_State(Aspose::Email::Outlook::MapiTaskState::NotAssigned);
// Set the weekly recurrence
auto rec = System::MakeObject<MapiCalendarDailyRecurrencePattern>();
rec->set_PatternType(Aspose::Email::Outlook::MapiCalendarRecurrencePatternType::Day);
rec->set_Period(1);
rec->set_WeekStartDay(System::DayOfWeek::Sunday);
rec->set_EndType(Aspose::Email::Outlook::MapiCalendarRecurrenceEndType::NeverEnd);
rec->set_OccurrenceCount(0);
task->set_Recurrence(rec);
task->Save(dataDir + L"AsposeDaily_out.msg", Aspose::Email::Outlook::TaskSaveFormat::Msg);
// Set the weekly recurrence
auto rec1 = System::MakeObject<MapiCalendarWeeklyRecurrencePattern>();
rec1->set_PatternType(Aspose::Email::Outlook::MapiCalendarRecurrencePatternType::Week);
rec1->set_Period(1);
rec1->set_DayOfWeek(Aspose::Email::Outlook::MapiCalendarDayOfWeek::Wednesday);
rec1->set_EndType(Aspose::Email::Outlook::MapiCalendarRecurrenceEndType::NeverEnd);
rec1->set_OccurrenceCount(0);
task->set_Recurrence(rec1);
task->Save(dataDir + L"AsposeWeekly_out.msg", Aspose::Email::Outlook::TaskSaveFormat::Msg);
// Set the monthly recurrence
auto recMonthly = System::MakeObject<MapiCalendarMonthlyRecurrencePattern>();
recMonthly->set_PatternType(Aspose::Email::Outlook::MapiCalendarRecurrencePatternType::Month);
recMonthly->set_Period(1);
recMonthly->set_EndType(Aspose::Email::Outlook::MapiCalendarRecurrenceEndType::NeverEnd);
recMonthly->set_Day(30);
recMonthly->set_OccurrenceCount(0);
recMonthly->set_WeekStartDay(System::DayOfWeek::Sunday);
task->set_Recurrence(recMonthly);
//task.Save(dataDir + "AsposeMonthly_out.msg", TaskSaveFormat.Msg);
// Set the yearly recurrence
auto recYearly = System::MakeObject<MapiCalendarMonthlyRecurrencePattern>();
recYearly->set_PatternType(Aspose::Email::Outlook::MapiCalendarRecurrencePatternType::Month);
recYearly->set_EndType(Aspose::Email::Outlook::MapiCalendarRecurrenceEndType::NeverEnd);
recYearly->set_OccurrenceCount(10);
recYearly->set_Period(12);
task->set_Recurrence(recYearly);
//task.Save(dataDir + "AsposeYearly_out.msg", TaskSaveFormat.Msg);