使用 EWS API 对 Exchange 邮件进行归档

Contents
[ ]

Aspose.Email for .NET 提供了全面的 API,用于管理和处理 Exchange 服务器上的电子邮件。本指南演示了如何列出 Exchange 邮箱收件箱文件夹中的邮件,并使用该 API 进行编程归档。 IEWSClient 接口。该 IEWSClient.ArchiveItem 方法的 IEWSClient 接口允许您将项目移动到用户的归档邮箱。它提供了下面列出的四个重载:

以下代码示例演示了如何使用 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();