public static void Run()
{
// ExStart:MoveMessageFromOneFolderToAnotherUsingExchangeClient
string mailboxURI = "https://Ex2003/exchange/administrator"; // WebDAV
string username = "administrator";
string password = "pwd";
string domain = "domain.local";
Console.WriteLine("Connecting to Exchange Server....");
NetworkCredential credential = new NetworkCredential(username, password, domain);
ExchangeClient client = new ExchangeClient(mailboxURI, credential);
ExchangeMailboxInfo mailboxInfo = client.GetMailboxInfo();
// List all messages from Inbox folder
Console.WriteLine("Listing all messages from Inbox....");
ExchangeMessageInfoCollection msgInfoColl = client.ListMessages(mailboxInfo.InboxUri);
foreach (ExchangeMessageInfo msgInfo in msgInfoColl)
{
// Nove message to "Processed" folder, after processing certain messages based on some criteria
if (msgInfo.Subject != null &&
msgInfo.Subject.ToLower().Contains("process this message") == true)
{
client.MoveItems(msgInfo.UniqueUri, client.MailboxInfo.RootUri + "/Processed/" + msgInfo.Subject);
Console.WriteLine("Message moved...." + msgInfo.Subject);
}
else
{
// Do something else
}
}
// ExEnd:MoveMessageFromOneFolderToAnotherUsingExchangeClient
}
}