Trabajando con Tareas en Exchange Server
Trabajando con Tareas
Aspose.Email admite el procesamiento de tareas en Exchange Server utilizando la clase ExchangeTask. Se pueden utilizar diferentes propiedades expuestas por ExchangeTask, como Subject, Status, DueDate y Priority, para configurar la tarea en Exchange. La clase IEWSClient expone funciones como CreateTask, UpdateTask y DeleteTask, que se utilizan para procesar tareas en el servidor de Exchange. Este artículo muestra cómo:
- Crear una nueva tarea.
- Establecer la zona horaria de una tarea.
- Actualizar una tarea.
- Eliminar una tarea.
- Enviar Solicitud de Tarea
- Guardar Tarea en Disco
Crear Nueva Tarea
El siguiente fragmento de código muestra cómo crear una nueva tarea.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-C | |
// Create instance of EWSClient class by giving credentials | |
System::SharedPtr<IEWSClient> client = GetExchangeEWSClient(GetExchangeTestUser()); | |
// Create Exchange task object | |
System::SharedPtr<ExchangeTask> task = System::MakeObject<ExchangeTask>(); | |
// Set task subject and status to In progress | |
task->set_Subject(u"New-Test"); | |
task->set_Status(Aspose::Email::Clients::Exchange::WebService::ExchangeTaskStatus::InProgress); | |
client->CreateTask(client->get_MailboxInfo()->get_TasksUri(), task); |
Especificando la Zona Horaria
La interfaz IEWSClient y ExchangeTask proporcionan la propiedad TimeZoneId para establecer información de zona horaria al crear una tarea. El siguiente fragmento de código muestra cómo especificar la Zona Horaria.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-C | |
client->set_TimezoneId(u"Central Europe Standard Time"); |
Actualizar Tarea
Los siguientes fragmentos de código muestran cómo actualizar una tarea en el servidor de Exchange.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-C | |
// Create instance of ExchangeClient class by giving credentials | |
System::SharedPtr<IEWSClient> client = GetExchangeEWSClient(GetExchangeTestUser()); | |
// Get all tasks info collection from exchange | |
System::SharedPtr<ExchangeMessageInfoCollection> tasks = client->ListMessages(client->get_MailboxInfo()->get_TasksUri()); | |
// Parse all the tasks info in the list | |
for (auto info : System::IterateOver(tasks)) | |
{ | |
// Fetch task from exchange using current task info | |
System::SharedPtr<ExchangeTask> task = client->FetchTask(info->get_UniqueUri()); | |
// Update the task status to NotStarted | |
task->set_Status(Aspose::Email::Clients::Exchange::WebService::ExchangeTaskStatus::NotStarted); | |
// Set the task due date | |
task->set_DueDate(System::DateTime(2013, 2, 26)); | |
// Set task priority | |
task->set_Priority(Aspose::Email::MailPriority::Low); | |
// Update task on exchange | |
client->UpdateTask(task); | |
} |
Eliminar Tarea
El siguiente fragmento de código muestra cómo eliminar una tarea en el servidor de Exchange.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-C | |
// Create instance of ExchangeClient class by giving credentials | |
System::SharedPtr<IEWSClient> client = GetExchangeEWSClient(GetExchangeTestUser()); | |
// Get all tasks info collection from exchange | |
System::SharedPtr<ExchangeMessageInfoCollection> tasks = client->ListMessages(client->get_MailboxInfo()->get_TasksUri()); | |
// Parse all the tasks info in the list | |
for (auto info : System::IterateOver(tasks)) | |
{ | |
// Fetch task from exchange using current task info | |
System::SharedPtr<ExchangeTask> task = client->FetchTask(info->get_UniqueUri()); | |
// Check if the current task fulfills the search criteria | |
if (System::ObjectExt::Equals(task->get_Subject(), u"test")) | |
{ | |
//Delete task from exchange | |
client->DeleteTask(task->get_UniqueUri(), Aspose::Email::Clients::Exchange::WebService::DeleteTaskOptions::DeletePermanently); | |
} | |
} |
Enviando Solicitud de Tarea
El servicio Aspose.Email Exchange proporciona la capacidad de enviar solicitudes de tarea similares a Outlook. El siguiente fragmento de código muestra cómo cargar un mensaje de solicitud de tarea desde el disco y enviarlo utilizando el IEWSClient.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-C | |
System::String dataDir = GetDataDir_Exchange(); | |
// Create instance of ExchangeClient class by giving credentials | |
System::SharedPtr<IEWSClient> client = GetExchangeEWSClient(GetExchangeTestUser()); | |
System::SharedPtr<MsgLoadOptions> options = System::MakeObject<MsgLoadOptions>(); | |
options->set_PreserveTnefAttachments(true); | |
// load task from .msg file | |
System::SharedPtr<MailMessage> eml = MailMessage::Load(dataDir + u"task.msg", options); | |
eml->set_From(MailAddress::to_MailAddress(u"firstname.lastname@domain.com")); | |
eml->get_To()->Clear(); | |
eml->get_To()->Add(System::MakeObject<MailAddress>(u"firstname.lastname@domain.com")); | |
client->Send(eml); |
Guardar Tarea en Disco
Aspose.Email también permite guardar Tareas de Exchange en disco en formato MSG de Outlook. El siguiente fragmento de código muestra cómo guardar una tarea en disco.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-C | |
System::SharedPtr<ExchangeTask> task = System::MakeObject<ExchangeTask>(); | |
task->set_Subject(System::String(u"TASK-ID - ") + System::Guid::NewGuid()); | |
task->set_Status(Aspose::Email::Clients::Exchange::WebService::ExchangeTaskStatus::InProgress); | |
task->set_StartDate(System::DateTime::get_Now()); | |
task->set_DueDate(task->get_StartDate().AddDays(3)); | |
System::StaticCast<Calendar::Task>(task)->Save(dstEmail); |