Microsoft Exchange Server is a widely used collaboration platform that provides email, contact management, calendaring, and other services. In the previous post, we have shown you how to access and read emails from MS Exchange Server programmatically in a .NET application. However, you may also need to copy emails from one folder to another on Exchange Server. To achieve that, this article shows how to move emails to a particular folder on MS Exchange Server in C# .NET.
- .NET API to Move Emails on Microsoft Exchange Server
- Move Existing Email to a Folder on MS Exchange Server
- Move New Email to a Folder on MS Exchange Server
C# .NET API to Move Emails on Microsoft Exchange Server
To move the emails on MS Exchange Server, we will use Aspose.Email for .NET. The API provides simple ways to connect to and work with MS Exchange Server. You can install it via NuGet or download its DLL.
PM> Install-Package Aspose.Email
Move Email to a Folder on MS Exchange Server in C#
The following are the steps to move emails to a particular folder on MS Exchange Server in C#.
- First, initialize IEWSClient object using username, password, domain and URI.
- Then, get list of email messages in an ExchangeMessageInfoCollection object using IEWSClient.ListMessages(IEWSClient.MailboxInfo.InboxUri) method.
- After that, loop through each ExchangeMessageInfo message and filter the required one(s).
- Then, get the URI of message to be moved using ExchangeMessageInfo.UniqueUri property.
- Finally, move email message using IEWSClient.CopyItem(string URI, IEWSClient.MailboxInfo.DeletedItemsUri) method.
The following code sample shows how to move an email to a folder on MS Exchange Server in C# .NET.
Move New Email to a Folder on MS Exchange Server
You can also move a newly created email to a particular folder in MS Exchange Server. The following are the steps to perform this operation.
- First, initialize IEWSClient object using username, password, domain and URI.
- Then, create a new message using MailMessage class.
- After that, get email message’s URI returned by IEWSClient.AppendMessage(MailMessage) method.
- Finally, move email message using IEWSClient.CopyItem(string URI, IEWSClient.MailboxInfo.OutboxUri) method.
The following code sample shows how to move a new email message to a folder in MS Exchange Server.
Get a Free API License
You can get a free temporary license to use Aspose.Email for .NET without evaluation limitations.
Conclusion
In this article, you have learned how to move emails to a particular folder in Microsoft Exchange Server using C#. Furthermore, you have seen how to move a newly created email message to a specific folder in Exchange Server. Besides, you can explore the documentation to read more about Aspose.Email for .NET. Also, you can ask your questions via our forum.