EWS API を使用した Exchange メールのアーカイブ
Contents
[
Hide
]
Aspose.Email for .NET は、Exchange Server 上のメールを管理・処理する包括的な API を提供します。このガイドでは、Exchange メールボックスの受信トレイフォルダー内のメールを一覧表示し、プログラムでアーカイブする方法を示します。 IEWSClient インターフェイスです。 IEWSClient.ArchiveItem メソッド( IEWSClient インターフェイスは、アイテムをユーザーのアーカイブメールボックスに移動できるようにします。以下の4つのオーバーロードが用意されています:
- ArchiveItem(string sourceFolderUri, Appointment appointment)
- ArchiveItem(string sourceFolderUri, ExchangeTask task)
- ArchiveItem(string sourceFolderUri, MapiMessageItemBase item)
- ArchiveItem(string sourceFolderUri, string uniqueId)
以下のコードサンプルは、Aspose.Email を使用して Exchange サーバーに接続し、メッセージを一覧表示し、次の方法でアーカイブする方法を示しています。 IEWSClient.ArchiveItem メソッドです。メールの保存は、UniqueUri を使用して各アイテムをアーカイブメールボックスに移動することで実現します。
const string mailboxUri = "<HOST>";
const string domain = @"";
const string username = @"<USERNAME>";
const string password = @"<PASSWORD>";
NetworkCredential credentials = new NetworkCredential(username, password, domain);
IEWSClient client = EWSClient.GetEWSClient(mailboxUri, credentials);
ExchangeMessageInfoCollection msgCollection = client.ListMessages(client.MailboxInfo.InboxUri);
foreach (ExchangeMessageInfo msgInfo in msgCollection)
{
Console.WriteLine("Subject:" + msgInfo.Subject);
client.ArchiveItem(client.MailboxInfo.InboxUri, msgInfo.UniqueUri);
}
client.Dispose();