Read the complete article on how to move emails to a folder in MS Exchange Server in C#: https://blog.aspose.com/2022/02/28/move-emails-to-folders-in-ms-exchange-server-csharp/
Last active
March 30, 2022 04:46
Move Email to a Folder in Microsoft Exchange Server using C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try | |
{ | |
// Create instance of EWSClient class by giving credentials | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
// Call ListMessages method to list messages info from Inbox | |
ExchangeMessageInfoCollection msgCollection = client.ListMessages(client.MailboxInfo.InboxUri); | |
// Loop through the collection to get Message URI | |
foreach (ExchangeMessageInfo msgInfo in msgCollection) | |
{ | |
if (msgInfo.From.Address.Contains("jhon.vick")) | |
{ | |
String strMessageURI = msgInfo.UniqueUri; | |
// Copy to particular folder | |
string newMessageUri = client.CopyItem(strMessageURI, client.MailboxInfo.DeletedItemsUri); | |
} | |
} | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine(ex.Message); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try | |
{ | |
// Create instance of EWSClient class by giving credentials | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
// Create messge | |
MailMessage message = new MailMessage("from@domain.com", "to@domain.com", "EMAILNET-34997 - " + Guid.NewGuid().ToString(), "EMAILNET-34997 Exchange: Copy a message and get reference to the new Copy item"); | |
// Get message URI | |
string messageUri = client.AppendMessage(message); | |
// Copy message | |
string newMessageUri = client.CopyItem(messageUri, client.MailboxInfo.OutboxUri); | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine(ex.Message); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment