We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to move Items from a inbox to a folder created in Office 365 using EWS Client

Hi,
I am using below code

IEWSClient emailClient = null;
string folderName = DateTime.Now.ToString(“dd-MM-yyyy”);
//Creating a folder
emailClient.CreateFolder(emailClient.MailboxInfo.InboxUri, folderName);

How to move an email from the inbox to a particular folder created?

Thanks in Advance.

@Gowtham5555,

You need to read the messages from your inbox folder, processes the messages based on some criteria (if any criteria is required) and move the messages to the required folder. Please use the following code snippet to move the messages from inbox to any other folder using EWSClient.

CODE:

// Create instance of IEWSClient class by giving credentials
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain");

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)
{
    // Move 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.MoveItem(mailboxInfo.DeletedItemsUri, msgInfo.UniqueUri); // EWS
         Console.WriteLine("Message moved...." + msgInfo.Subject);
    }
    else
    {
         // Do something else
    }
}

Visit the following links for details:

Hi,

I want to move items to a folder created by me and not the public folders.

Thanks
Gowtham A

@Gowtham5555,

Please use the following code snippet to create and get URI to the folder created by you (custom folder). Once you have the custom folder (destination folder) URI, you can copy the message.

CODE:

// CREATE CUSTOM FOLDER
// Create instance of EWSClient class by giving credentials
Aspose.Email.Clients.Exchange.WebService.IEWSClient client = Aspose.Email.Clients.Exchange.WebService.EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain");

string folderName1 = "My-Emails";
client.CreateFolder(client.MailboxInfo.InboxUri, folderName1);

// Create ExchangeMailboxInfo instance
Aspose.Email.Clients.Exchange.ExchangeMailboxInfo mailbox = client.GetMailboxInfo();

Aspose.Email.Clients.Exchange.ExchangeFolderInfo CustfolderInfo = new 
Aspose.Email.Clients.Exchange.ExchangeFolderInfo();
// Check if specified custom folder exisits
client.FolderExists(mailbox.InboxUri, folderName1, out CustfolderInfo);

//if custom folder exists
if (CustfolderInfo != null)
{
    string sUriOfCustomFolder = CustfolderInfo.Uri;
    // Call MoveItem method of IEWSClient and pass URI of the message to be moved and URI of your custom folder.
    
    // List all messages from Inbox folder
   Console.WriteLine("Listing all messages from Inbox....");
   ExchangeMessageInfoCollection msgInfoColl = client.ListMessages(mailbox.InboxUri);
   foreach (ExchangeMessageInfo msgInfo in msgInfoColl)
   {
         // Move 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.MoveItem(msgInfo.UniqueUri, sUriOfCustomFolder);
                 Console.WriteLine("Message moved...." + msgInfo.Subject);
          }
          else
          {
               // Do something else
          }
   }

}