Exchange Server のタスクの操作

タスクの操作

Aspose.Email は Exchange Server 上のタスク処理を ExchangeTask クラス。異なるプロパティが公開されています ExchangeTask、件名やステータス(ExchangeTaskStatus)、期限日と優先度は、Exchange のタスク設定に使用できます。これらは IEWSClient クラスは次のようなメソッドを公開します CreateTask, FetchTask, UpdateTask および DeleteItem これらは Exchange Server 上のタスク処理に使用されます。この記事では、以下の方法を示します:

  • 新しいタスクを作成します。
  • タスクのタイムゾーンを設定します。
  • タスクを更新します。
  • タスクを削除します。
  • タスク要求を送信
  • タスクをディスクに保存

本記事のサンプルは以下のヘッダーと名前空間を使用しています:

#include <MailMessage.h>
#include <MailAddress.h>
#include <MailAddressCollection.h>
#include <MailPriority.h>
#include <MsgLoadOptions.h>
#include <Mapi/TaskSaveFormat.h>
#include <Clients/Exchange/WebService/EWSClient/EWSClient.h>
#include <Clients/Exchange/WebService/EWSClient/IEWSClient.h>
#include <Clients/Exchange/WebService/EWSClient/DeletionOptions.h>
#include <Clients/Exchange/WebService/Tasks/ExchangeTask.h>
#include <Clients/Exchange/WebService/Tasks/ExchangeTaskStatus.h>
#include <Clients/Exchange/ExchangeMailboxInfo.h>
#include <Clients/Exchange/ExchangeMessageInfo.h>
#include <Clients/Exchange/ExchangeMessageInfoCollection.h>
#include <system/date_time.h>

using namespace System;
using namespace Aspose::Email;
using namespace Aspose::Email::Clients::Exchange;
using namespace Aspose::Email::Clients::Exchange::WebService;

新しいタスクを作成

CreateTask() 指定フォルダー(ここではメールボックスのデフォルトTasksフォルダー)にタスクを作成し、新規タスクのURIを返します。

SharedPtr<IEWSClient> client = EWSClient::GetEWSClient(u"https://outlook.office365.com/ews/exchange.asmx", u"username", u"password");

SharedPtr<ExchangeTask> task = MakeObject<ExchangeTask>();
task->set_Subject(u"New-Test");
task->set_Status(ExchangeTaskStatus::InProgress);

String taskUri = client->CreateTask(client->get_MailboxInfo()->get_TasksUri(), task);
Console::WriteLine(u"Task created: " + taskUri);

client->Dispose();

タイムゾーンの指定

タスクの日時はクライアントのタイムゾーンで解釈されます。 set_TimezoneId() の IEWSClient タスク作成または更新前に、Windows IDでこのタイムゾーンを設定します。

SharedPtr<IEWSClient> client = EWSClient::GetEWSClient(u"https://outlook.office365.com/ews/exchange.asmx", u"username", u"password");

client->set_TimezoneId(u"Central Europe Standard Time");

SharedPtr<ExchangeTask> task = MakeObject<ExchangeTask>();
task->set_Subject(u"Task in Central European time");
task->set_StartDate(DateTime::get_Now());
task->set_DueDate(DateTime::get_Now().AddDays(3));
client->CreateTask(client->get_MailboxInfo()->get_TasksUri(), task);

client->Dispose();

タスクの更新

ListMessages() Tasksフォルダーのアイテムを一覧表示します; FetchTask() URIでタスクを読み取ります。サンプルはステータス、期限日、優先度を変更し、 UpdateTask().

SharedPtr<IEWSClient> client = EWSClient::GetEWSClient(u"https://outlook.office365.com/ews/exchange.asmx", u"username", u"password");

for (SharedPtr<ExchangeMessageInfo> info : client->ListMessages(client->get_MailboxInfo()->get_TasksUri()))
{
    SharedPtr<ExchangeTask> task = client->FetchTask(info->get_UniqueUri());

    task->set_Status(ExchangeTaskStatus::NotStarted);
    task->set_DueDate(DateTime::get_Now().AddDays(7));
    task->set_Priority(MailPriority::Low);

    client->UpdateTask(task);
}

client->Dispose();

タスクの削除

タスクはメールボックスの他のアイテムと同様に削除されます: DeleteItem() そのURIと DeletionOptions - get_DeletePermanently() タスクを削除します、 get_MoveToDeletedItems() Deleted Itemsフォルダーに移動します。サンプルは件名が「test」のタスクを削除します。

SharedPtr<IEWSClient> client = EWSClient::GetEWSClient(u"https://outlook.office365.com/ews/exchange.asmx", u"username", u"password");

for (SharedPtr<ExchangeMessageInfo> info : client->ListMessages(client->get_MailboxInfo()->get_TasksUri()))
{
    SharedPtr<ExchangeTask> task = client->FetchTask(info->get_UniqueUri());
    if (task->get_Subject() == u"test")
    {
        client->DeleteItem(task->get_UniqueUri(), DeletionOptions::get_DeletePermanently());
    }
}

client->Dispose();

タスク要求の送信

Aspose.Email ExchangeサービスはOutlookと同様にタスク要求を送信する機能を提供します。次のコードスニペットはMSGファイルからタスク要求メッセージを読み込み、 IEWSClient. MsgLoadOptions::set_PreserveTnefAttachments() タスクデータをTNEF形式のまま保持するため、受信者はタスク要求を受け取り、単なるメッセージではありません。

SharedPtr<IEWSClient> client = EWSClient::GetEWSClient(u"https://outlook.office365.com/ews/exchange.asmx", u"username", u"password");

SharedPtr<MsgLoadOptions> options = MakeObject<MsgLoadOptions>();
options->set_PreserveTnefAttachments(true);

SharedPtr<MailMessage> message = MailMessage::Load(u"task.msg", options);
message->set_From(MakeObject<MailAddress>(u"firstname.lastname@domain.com"));
message->get_To()->Clear();
message->get_To()->Add(MakeObject<MailAddress>(u"firstname.lastname@domain.com"));
client->Send(message);

client->Dispose();

タスクをディスクに保存

Aspose.Email はExchangeタスクをOutlook MSG形式でディスクに保存することも可能です: Save() メソッド ExchangeTask ファイル名と形式を受け取ります、 TaskSaveFormat::Msg. タスクはサーバーに保存する必要はありません。

SharedPtr<ExchangeTask> task = MakeObject<ExchangeTask>();
task->set_Subject(u"Task to save");
task->set_Status(ExchangeTaskStatus::InProgress);
task->set_StartDate(DateTime::get_Now());
task->set_DueDate(task->get_StartDate().AddDays(3));

task->Save(u"task_out.msg", Mapi::TaskSaveFormat::Msg);